From 983c158da7723eb00a376bd31db76709da4d0260 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 10 Mar 2016 18:21:25 +0100 Subject: Refs #24227 -- Replaced M2M isinstance checks by field.many_to_many Thanks Markus Holtermann, Collin Anderson and Tim Graham for the reviews. --- django/forms/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'django/forms') diff --git a/django/forms/models.py b/django/forms/models.py index 4422882315..067f601493 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -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. -- cgit v1.3