summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2010-10-08 23:55:38 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2010-10-08 23:55:38 +0000
commitae448e4439f306aeec4989739f137e7d64ab63ef (patch)
treefdb151a17bbf98faa7e371cfe5d42dbae25f4a80 /tests
parent3ab1a0c7d6bd88063e526a8ec36e1468b9364f9e (diff)
[1.2.X] Fixed #13241. order_with_respect_to now works with ForeignKeys who refer to their model lazily (i.e. with a string). Thanks to Gabriel Grant for the patch. This is a backport of [14045].
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14046 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/order_with_respect_to/models.py10
-rw-r--r--tests/modeltests/order_with_respect_to/tests.py11
2 files changed, 20 insertions, 1 deletions
diff --git a/tests/modeltests/order_with_respect_to/models.py b/tests/modeltests/order_with_respect_to/models.py
index 7e4acdadf7..59f01d4cd1 100644
--- a/tests/modeltests/order_with_respect_to/models.py
+++ b/tests/modeltests/order_with_respect_to/models.py
@@ -17,3 +17,13 @@ class Answer(models.Model):
def __unicode__(self):
return unicode(self.text)
+
+class Post(models.Model):
+ title = models.CharField(max_length=200)
+ parent = models.ForeignKey("self", related_name="children", null=True)
+
+ class Meta:
+ order_with_respect_to = "parent"
+
+ def __unicode__(self):
+ return self.title
diff --git a/tests/modeltests/order_with_respect_to/tests.py b/tests/modeltests/order_with_respect_to/tests.py
index 4f1c8a4e16..328d968fd4 100644
--- a/tests/modeltests/order_with_respect_to/tests.py
+++ b/tests/modeltests/order_with_respect_to/tests.py
@@ -2,7 +2,7 @@ from operator import attrgetter
from django.test import TestCase
-from models import Question, Answer
+from models import Post, Question, Answer
class OrderWithRespectToTests(TestCase):
@@ -60,3 +60,12 @@ class OrderWithRespectToTests(TestCase):
],
attrgetter("text")
)
+
+ def test_recursive_ordering(self):
+ p1 = Post.objects.create(title='1')
+ p2 = Post.objects.create(title='2')
+ p1_1 = Post.objects.create(title="1.1", parent=p1)
+ p1_2 = Post.objects.create(title="1.2", parent=p1)
+ p2_1 = Post.objects.create(title="2.1", parent=p2)
+ p1_3 = Post.objects.create(title="1.3", parent=p1)
+ self.assertEqual(p1.get_post_order(), [p1_1.pk, p1_2.pk, p1_3.pk])