summaryrefslogtreecommitdiff
path: root/tests/model_forms/tests.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-08-30 10:06:10 -0400
committerTim Graham <timograham@gmail.com>2017-08-31 09:41:04 -0400
commit20c03399d8fd03484f3ed33d93691c29c2ff5aaf (patch)
treeb9674327e45fe969fba0166651dd203c04280063 /tests/model_forms/tests.py
parent80a0016c49331bf0a14ef76e714acbff6c6640bd (diff)
[1.11.x] Fixed #27998, #28543 -- Restored logging of ManyToManyField changes in admin's object history.
And prevented ManyToManyField initial data in model forms from being affected by subsequent model changes. Regression in 56a55566a791a11420fe96f745b7489e756fc931. Partial backport of e5bd585c6eb1e13e2f8aac030b33c077b0b70c05 and 15b465c584f49a1d43b6c18796f83521ee4ffc22 from master
Diffstat (limited to 'tests/model_forms/tests.py')
-rw-r--r--tests/model_forms/tests.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index f3317f59de..b14e0e2389 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -3142,3 +3142,18 @@ class StrictAssignmentTests(TestCase):
'__all__': ['Cannot set attribute'],
'title': ['This field cannot be blank.']
})
+
+
+class ModelToDictTests(TestCase):
+ def test_many_to_many(self):
+ """Data for a ManyToManyField is a list rather than a lazy QuerySet."""
+ blue = Colour.objects.create(name='blue')
+ red = Colour.objects.create(name='red')
+ item = ColourfulItem.objects.create()
+ item.colours.set([blue])
+ data = model_to_dict(item)['colours']
+ self.assertEqual(data, [blue])
+ item.colours.set([red])
+ # If data were a QuerySet, it would be reevaluated here and give "red"
+ # instead of the original value.
+ self.assertEqual(data, [blue])