mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[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 ofe5bd585c6eand15b465c584from master
This commit is contained in:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user