From 38c43b2a5c9e47f2fabb60521c1224825ebcc833 Mon Sep 17 00:00:00 2001 From: Collin Anderson Date: Thu, 31 Mar 2016 18:24:40 -0400 Subject: [PATCH] Refs #24227 -- Partially reverted replacement of M2M isinstance checks by field.many_to_many. This fixes django-taggit and reflects some places where duck-typing may not be appropriate. --- django/contrib/admin/options.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 287e155347..e8fd56dbad 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -136,8 +136,8 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)): if db_field.choices: return self.formfield_for_choice_field(db_field, request, **kwargs) - # Foreign key or many-to-many fields - if db_field.many_to_many or isinstance(db_field, models.ForeignKey): + # ForeignKey or ManyToManyFields + if isinstance(db_field, models.ManyToManyField) or isinstance(db_field, models.ForeignKey): # Combine the field kwargs with any options for formfield_overrides. # Make sure the passed in **kwargs override anything in # formfield_overrides because **kwargs is more specific, and should @@ -148,7 +148,7 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)): # Get the correct formfield. if isinstance(db_field, models.ForeignKey): formfield = self.formfield_for_foreignkey(db_field, request, **kwargs) - elif db_field.many_to_many: + elif isinstance(db_field, models.ManyToManyField): formfield = self.formfield_for_manytomany(db_field, request, **kwargs) # For non-raw_id fields, wrap the widget with a wrapper that adds @@ -1400,7 +1400,7 @@ class ModelAdmin(BaseModelAdmin): except FieldDoesNotExist: continue # We have to special-case M2Ms as a list of comma-separated PKs. - if f.many_to_many: + if isinstance(f, models.ManyToManyField): initial[k] = initial[k].split(",") return initial