Author: jacob
Date: 2008-09-01 16:04:01 -0500 (Mon, 01 Sep 2008)
New Revision: 8814
Modified:
django/trunk/django/db/models/fields/related.py
django/trunk/tests/regressiontests/model_inheritance_regress/models.py
Log:
Fixed #8076: fixed `get_(next/previous)_by_date` when used with subclasses.
Thanks, bjornkri and jan_oberst.
Modified: django/trunk/django/db/models/fields/related.py
===================================================================
--- django/trunk/django/db/models/fields/related.py 2008-09-01 20:45:34 UTC
(rev 8813)
+++ django/trunk/django/db/models/fields/related.py 2008-09-01 21:04:01 UTC
(rev 8814)
@@ -142,7 +142,12 @@
if hasattr(value, 'as_sql'):
sql, params = value.as_sql()
return QueryWrapper(('(%s)' % sql), params)
- if lookup_type == 'exact':
+
+ # FIXME: lt and gt are explicitally allowed to make
+ # get_(next/prev)_by_date work; other lookups are not allowed since
that
+ # gets messy pretty quick. This is a good candidate for some
refactoring
+ # in the future.
+ if lookup_type in ['exact', 'gt', 'lt']:
return [pk_trace(value)]
if lookup_type in ('range', 'in'):
return [pk_trace(v) for v in value]
Modified: django/trunk/tests/regressiontests/model_inheritance_regress/models.py
===================================================================
--- django/trunk/tests/regressiontests/model_inheritance_regress/models.py
2008-09-01 20:45:34 UTC (rev 8813)
+++ django/trunk/tests/regressiontests/model_inheritance_regress/models.py
2008-09-01 21:04:01 UTC (rev 8814)
@@ -59,6 +59,18 @@
class SelfRefChild(SelfRefParent):
child_data = models.IntegerField()
+class Article(models.Model):
+ headline = models.CharField(max_length=100)
+ pub_date = models.DateTimeField()
+ class Meta:
+ ordering = ('-pub_date', 'headline')
+
+ def __unicode__(self):
+ return self.headline
+
+class ArticleWithAuthor(Article):
+ author = models.CharField(max_length=100)
+
__test__ = {'API_TESTS':"""
# Regression for #7350, #7202
# Check that when you create a Parent object with a specific reference to an
@@ -194,4 +206,29 @@
>>> obj = SelfRefChild.objects.create(child_data=37, parent_data=42)
>>> obj.delete()
+# Regression tests for #8076 - get_(next/previous)_by_date should
+>>> c1 = ArticleWithAuthor(headline='ArticleWithAuthor 1', author="Person 1",
pub_date=datetime.datetime(2005, 8, 1, 3, 0))
+>>> c1.save()
+>>> c2 = ArticleWithAuthor(headline='ArticleWithAuthor 2', author="Person 2",
pub_date=datetime.datetime(2005, 8, 1, 10, 0))
+>>> c2.save()
+>>> c3 = ArticleWithAuthor(headline='ArticleWithAuthor 3', author="Person 3",
pub_date=datetime.datetime(2005, 8, 2))
+>>> c3.save()
+
+>>> c1.get_next_by_pub_date()
+<ArticleWithAuthor: ArticleWithAuthor 2>
+>>> c2.get_next_by_pub_date()
+<ArticleWithAuthor: ArticleWithAuthor 3>
+>>> c3.get_next_by_pub_date()
+Traceback (most recent call last):
+ ...
+DoesNotExist: ArticleWithAuthor matching query does not exist.
+>>> c3.get_previous_by_pub_date()
+<ArticleWithAuthor: ArticleWithAuthor 2>
+>>> c2.get_previous_by_pub_date()
+<ArticleWithAuthor: ArticleWithAuthor 1>
+>>> c1.get_previous_by_pub_date()
+Traceback (most recent call last):
+ ...
+DoesNotExist: ArticleWithAuthor matching query does not exist.
+
"""}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---