diff options
| author | Tim Graham <timograham@gmail.com> | 2016-05-11 10:12:59 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-05-11 10:12:59 -0400 |
| commit | 67d984413c9540074e4fe6aa033081a35cf192bc (patch) | |
| tree | dca54ef94c6af62b0b17a414eb3ad6d2bb9b7acd /django/forms | |
| parent | 8f6a1a15516629b30e2fa2c48d5e682f7955868c (diff) | |
Refs #24227 -- Removed ManyToManyField special casing in model_to_dict().
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/models.py | 16 |
1 files changed, 1 insertions, 15 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index 7ba98e1e26..0738421d9e 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -88,21 +88,7 @@ def model_to_dict(instance, fields=None, exclude=None): continue if exclude and f.name in exclude: continue - if f.many_to_many: - # If the object doesn't have a primary key yet, just use an empty - # list for its m2m fields. Calling f.value_from_object will raise - # an exception. - if instance.pk is None: - data[f.name] = [] - else: - # MultipleChoiceWidget needs a list of pks, not object instances. - qs = f.value_from_object(instance) - if qs._result_cache is not None: - data[f.name] = [item.pk for item in qs] - else: - data[f.name] = list(qs.values_list('pk', flat=True)) - else: - data[f.name] = f.value_from_object(instance) + data[f.name] = f.value_from_object(instance) return data |
