| 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 | |
| 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 | |