summaryrefslogtreecommitdiff
path: root/tests/order_with_respect_to
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2019-08-30 10:28:18 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-09-23 11:20:37 +0200
commitf97bbad908df128189eff77d98af9a25ed1ecf23 (patch)
tree29d101d94e9be700134a26d706b173477466110e /tests/order_with_respect_to
parentd9881a025c15d87b2a7883ee50771117450ea90d (diff)
downloaddjango-f97bbad908df128189eff77d98af9a25ed1ecf23.tar.gz
Fixed #13296 -- Fixed ordering by Options.order_with_respect_to after deleting objects.
Thanks Simon Meers for the original patch.
Diffstat (limited to 'tests/order_with_respect_to')
-rw-r--r--tests/order_with_respect_to/base_tests.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/order_with_respect_to/base_tests.py b/tests/order_with_respect_to/base_tests.py
index be67b068de..a99b632436 100644
--- a/tests/order_with_respect_to/base_tests.py
+++ b/tests/order_with_respect_to/base_tests.py
@@ -87,3 +87,17 @@ class BaseOrderWithRespectToTests:
self.Post.objects.create(title="2.1", parent=p2)
p1_3 = self.Post.objects.create(title="1.3", parent=p1)
self.assertSequenceEqual(p1.get_post_order(), [p1_1.pk, p1_2.pk, p1_3.pk])
+
+ def test_delete_and_insert(self):
+ q1 = self.Question.objects.create(text='What is your favorite color?')
+ q2 = self.Question.objects.create(text='What color is it?')
+ a1 = self.Answer.objects.create(text='Blue', question=q1)
+ a2 = self.Answer.objects.create(text='Red', question=q1)
+ a3 = self.Answer.objects.create(text='Green', question=q1)
+ a4 = self.Answer.objects.create(text='Yellow', question=q1)
+ self.assertSequenceEqual(q1.answer_set.all(), [a1, a2, a3, a4])
+ a3.question = q2
+ a3.save()
+ a1.delete()
+ new_answer = self.Answer.objects.create(text='Black', question=q1)
+ self.assertSequenceEqual(q1.answer_set.all(), [a2, a4, new_answer])