Ticket #17728: 17728.diff
File 17728.diff, 5.5 KB (added by , 13 years ago) |
---|
-
django/db/models/sql/where.py
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py index 1455ba6..d215f4c 100644
a b import datetime 8 8 from itertools import repeat 9 9 10 10 from django.utils import tree 11 from django.db.models.fields import Field 11 from django.db.models.fields import Field, DateTimeField 12 12 from django.db.models.sql.datastructures import EmptyResultSet, FullResultSet 13 13 14 14 # Connection types … … class WhereNode(tree.Node): 145 145 except EmptyShortCircuit: 146 146 raise EmptyResultSet 147 147 else: 148 # If the value is a datetime value, we need to take care converting it into 149 # proper db datettime type. 150 if isinstance(params_or_value, datetime.datetime): 151 params_or_value = connection.ops.value_to_db_datetime(params_or_value) 148 152 params = Field().get_db_prep_lookup(lookup_type, params_or_value, 149 153 connection=connection, prepared=True) 150 154 if isinstance(lvalue, tuple): -
tests/modeltests/timezones/models.py
diff --git a/tests/modeltests/timezones/models.py b/tests/modeltests/timezones/models.py index 9296edf..f0cc792 100644
a b class Event(models.Model): 6 6 class MaybeEvent(models.Model): 7 7 dt = models.DateTimeField(blank=True, null=True) 8 8 9 class Session(models.Model): 10 name = models.CharField(max_length=20) 11 12 class SessionEvent(models.Model): 13 dt = models.DateTimeField() 14 session = models.ForeignKey(Session, related_name='events') 15 9 16 class Timestamp(models.Model): 10 17 created = models.DateTimeField(auto_now_add=True) 11 18 updated = models.DateTimeField(auto_now=True) -
tests/modeltests/timezones/tests.py
diff --git a/tests/modeltests/timezones/tests.py b/tests/modeltests/timezones/tests.py index dc9cfb3..8184059 100644
a b from django.utils.tzinfo import FixedOffset 25 25 from django.utils.unittest import skipIf, skipUnless 26 26 27 27 from .forms import EventForm, EventSplitForm, EventModelForm 28 from .models import Event, MaybeEvent, Timestamp28 from .models import Event, MaybeEvent, Session, SessionEvent, Timestamp 29 29 30 30 31 31 # These tests use the EAT (Eastern Africa Time) and ICT (Indochina Time) … … class LegacyDatabaseTests(BaseDateTimeTests): 231 231 'dt__max': datetime.datetime(2011, 9, 1, 23, 20, 20), 232 232 }) 233 233 234 def test_query_annotation(self): 235 # Only min and max make sense for datetimes. 236 morning = Session.objects.create(name='morning') 237 afternoon = Session.objects.create(name='afternoon') 238 SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 23, 20, 20), session=afternoon) 239 SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 13, 20, 30), session=afternoon) 240 SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 3, 20, 40), session=morning) 241 morning_min_dt = datetime.datetime(2011, 9, 1, 3, 20, 40) 242 afternoon_min_dt = datetime.datetime(2011, 9, 1, 13, 20, 30) 243 self.assertQuerysetEqual( 244 Session.objects.annotate(dt=Min('events__dt')).order_by('dt'), 245 [morning_min_dt, afternoon_min_dt], 246 transform=lambda d: d.dt) 247 self.assertQuerysetEqual( 248 Session.objects.annotate(dt=Min('events__dt')).filter(dt__lt=afternoon_min_dt), 249 [morning_min_dt], 250 transform=lambda d: d.dt) 251 self.assertQuerysetEqual( 252 Session.objects.annotate(dt=Min('events__dt')).filter(dt__gte=afternoon_min_dt), 253 [afternoon_min_dt], 254 transform=lambda d: d.dt) 255 234 256 def test_query_dates(self): 235 257 Event.objects.create(dt=datetime.datetime(2011, 1, 1, 1, 30, 0)) 236 258 Event.objects.create(dt=datetime.datetime(2011, 1, 1, 4, 30, 0)) … … class NewDatabaseTests(BaseDateTimeTests): 412 434 'dt__max': datetime.datetime(2011, 9, 1, 23, 20, 20, tzinfo=EAT), 413 435 }) 414 436 437 def test_query_annotation(self): 438 # Only min and max make sense for datetimes. 439 morning = Session.objects.create(name='morning') 440 afternoon = Session.objects.create(name='afternoon') 441 SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 23, 20, 20, tzinfo=EAT), session=afternoon) 442 SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT), session=afternoon) 443 SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 3, 20, 40, tzinfo=EAT), session=morning) 444 morning_min_dt = datetime.datetime(2011, 9, 1, 3, 20, 40, tzinfo=EAT) 445 afternoon_min_dt = datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT) 446 self.assertQuerysetEqual( 447 Session.objects.annotate(dt=Min('events__dt')).order_by('dt'), 448 [morning_min_dt, afternoon_min_dt], 449 transform=lambda d: d.dt) 450 self.assertQuerysetEqual( 451 Session.objects.annotate(dt=Min('events__dt')).filter(dt__lt=afternoon_min_dt), 452 [morning_min_dt], 453 transform=lambda d: d.dt) 454 self.assertQuerysetEqual( 455 Session.objects.annotate(dt=Min('events__dt')).filter(dt__gte=afternoon_min_dt), 456 [afternoon_min_dt], 457 transform=lambda d: d.dt) 458 415 459 def test_query_dates(self): 416 460 # Same comment as in test_query_date_related_filters. 417 461 Event.objects.create(dt=datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=EAT))