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.
This commit is contained in:
parent
67d984413c
commit
38c43b2a5c
|
@ -136,8 +136,8 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)):
|
||||||
if db_field.choices:
|
if db_field.choices:
|
||||||
return self.formfield_for_choice_field(db_field, request, **kwargs)
|
return self.formfield_for_choice_field(db_field, request, **kwargs)
|
||||||
|
|
||||||
# Foreign key or many-to-many fields
|
# ForeignKey or ManyToManyFields
|
||||||
if db_field.many_to_many or isinstance(db_field, models.ForeignKey):
|
if isinstance(db_field, models.ManyToManyField) or isinstance(db_field, models.ForeignKey):
|
||||||
# Combine the field kwargs with any options for formfield_overrides.
|
# Combine the field kwargs with any options for formfield_overrides.
|
||||||
# Make sure the passed in **kwargs override anything in
|
# Make sure the passed in **kwargs override anything in
|
||||||
# formfield_overrides because **kwargs is more specific, and should
|
# formfield_overrides because **kwargs is more specific, and should
|
||||||
|
@ -148,7 +148,7 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)):
|
||||||
# Get the correct formfield.
|
# Get the correct formfield.
|
||||||
if isinstance(db_field, models.ForeignKey):
|
if isinstance(db_field, models.ForeignKey):
|
||||||
formfield = self.formfield_for_foreignkey(db_field, request, **kwargs)
|
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)
|
formfield = self.formfield_for_manytomany(db_field, request, **kwargs)
|
||||||
|
|
||||||
# For non-raw_id fields, wrap the widget with a wrapper that adds
|
# For non-raw_id fields, wrap the widget with a wrapper that adds
|
||||||
|
@ -1400,7 +1400,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||||
except FieldDoesNotExist:
|
except FieldDoesNotExist:
|
||||||
continue
|
continue
|
||||||
# We have to special-case M2Ms as a list of comma-separated PKs.
|
# 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(",")
|
initial[k] = initial[k].split(",")
|
||||||
return initial
|
return initial
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue