Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added some tests to modeltests/many_to_one that demonstrate a post-qu…

…eryset-refactor bug in dates(). Refs #7097

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7485 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9c53847ef43a67fafb1eff8e941a8ea75141c6d0 1 parent f0bc942
Adrian Holovaty authored April 28, 2008

Showing 1 changed file with 15 additions and 2 deletions. Show diff stats Hide diff stats

  1. 17  tests/modeltests/many_to_one/models.py
17  tests/modeltests/many_to_one/models.py
@@ -246,7 +246,7 @@ class Meta:
246 246
 >>> Reporter.objects.filter(article__reporter__exact=r).distinct()
247 247
 [<Reporter: John Smith>]
248 248
 
249  
-# Check that implied __exact also works
  249
+# Check that implied __exact also works.
250 250
 >>> Reporter.objects.filter(article__reporter=r).distinct()
251 251
 [<Reporter: John Smith>]
252 252
 
@@ -266,11 +266,24 @@ class Meta:
266 266
 >>> Reporter.objects.order_by('first_name')
267 267
 [<Reporter: John Smith>]
268 268
 
269  
-# Deletes using a join in the query
  269
+# You can delete using a JOIN in the query.
270 270
 >>> Reporter.objects.filter(article__headline__startswith='This').delete()
271 271
 >>> Reporter.objects.all()
272 272
 []
273 273
 >>> Article.objects.all()
274 274
 []
275 275
 
  276
+# Check that Article.objects.select_related().dates() works properly when
  277
+# there are multiple Articles with the same date but different foreign-key
  278
+# objects (Reporters).
  279
+>>> r1 = Reporter.objects.create(first_name='Mike', last_name='Royko', email='royko@suntimes.com')
  280
+>>> r2 = Reporter.objects.create(first_name='John', last_name='Kass', email='jkass@tribune.com')
  281
+>>> a1 = Article.objects.create(headline='First', pub_date=datetime(1980, 4, 23), reporter=r1)
  282
+>>> a2 = Article.objects.create(headline='Second', pub_date=datetime(1980, 4, 23), reporter=r2)
  283
+>>> Article.objects.select_related().dates('pub_date', 'day')
  284
+[datetime.datetime(1980, 4, 23, 0, 0)]
  285
+>>> Article.objects.select_related().dates('pub_date', 'month')
  286
+[datetime.datetime(1980, 4, 1, 0, 0)]
  287
+>>> Article.objects.select_related().dates('pub_date', 'year')
  288
+[datetime.datetime(1980, 1, 1, 0, 0)]
276 289
 """}

0 notes on commit 9c53847

Please sign in to comment.
Something went wrong with that request. Please try again.