diff options
| author | Tim Graham <timograham@gmail.com> | 2017-08-30 10:06:10 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-08-31 09:41:04 -0400 |
| commit | 20c03399d8fd03484f3ed33d93691c29c2ff5aaf (patch) | |
| tree | b9674327e45fe969fba0166651dd203c04280063 /django/forms/models.py | |
| parent | 80a0016c49331bf0a14ef76e714acbff6c6640bd (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 'django/forms/models.py')
| -rw-r--r-- | django/forms/models.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index db710a2ed2..0e80e19042 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -84,6 +84,7 @@ def model_to_dict(instance, fields=None, exclude=None): fields will be excluded from the returned dict, even if they are listed in the ``fields`` argument. """ + from django.db import models opts = instance._meta data = {} for f in chain(opts.concrete_fields, opts.private_fields, opts.many_to_many): @@ -94,6 +95,10 @@ def model_to_dict(instance, fields=None, exclude=None): if exclude and f.name in exclude: continue data[f.name] = f.value_from_object(instance) + # Evaluate ManyToManyField QuerySets to prevent subsequent model + # alteration of that field from being reflected in the data. + if isinstance(f, models.ManyToManyField): + data[f.name] = list(data[f.name]) return data |
