mirror of
https://github.com/django/django.git
synced 2025-10-26 23:26:08 +00:00
Refs #24227 -- Replaced M2M isinstance checks by field.many_to_many
Thanks Markus Holtermann, Collin Anderson and Tim Graham for the reviews.
This commit is contained in:
@@ -79,8 +79,6 @@ 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.
|
||||
"""
|
||||
# avoid a circular import
|
||||
from django.db.models.fields.related import ManyToManyField
|
||||
opts = instance._meta
|
||||
data = {}
|
||||
for f in chain(opts.concrete_fields, opts.virtual_fields, opts.many_to_many):
|
||||
@@ -90,7 +88,7 @@ def model_to_dict(instance, fields=None, exclude=None):
|
||||
continue
|
||||
if exclude and f.name in exclude:
|
||||
continue
|
||||
if isinstance(f, ManyToManyField):
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user