diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py index 87788c8f30..240b2f5563 100644 --- a/django/contrib/admin/checks.py +++ b/django/contrib/admin/checks.py @@ -217,10 +217,11 @@ class BaseModelAdminChecks(object): # be an extra field on the form. return [] else: - if field.many_to_many and not field.remote_field.through._meta.auto_created: + if (isinstance(field, models.ManyToManyField) and + not field.remote_field.through._meta.auto_created): return [ checks.Error( - "The value of '%s' cannot include the many-to-many field '%s' " + "The value of '%s' cannot include the ManyToManyField '%s', " "because that field manually specifies a relationship model." % (label, field_name), obj=obj.__class__, @@ -393,11 +394,11 @@ class BaseModelAdminChecks(object): return refer_to_missing_field(field=field_name, option=label, model=model, obj=obj, id='admin.E027') else: - if field.many_to_many or isinstance(field, (models.DateTimeField, models.ForeignKey)): + if isinstance(field, (models.DateTimeField, models.ForeignKey, models.ManyToManyField)): return [ checks.Error( "The value of '%s' refers to '%s', which must not be a DateTimeField, " - "a foreign key, or a many-to-many field." % (label, field_name), + "a ForeignKey, or a ManyToManyField." % (label, field_name), obj=obj.__class__, id='admin.E028', ) @@ -621,10 +622,10 @@ class ModelAdminChecks(BaseModelAdminChecks): id='admin.E108', ) ] - elif getattr(field, 'many_to_many', False): + elif isinstance(field, models.ManyToManyField): return [ checks.Error( - "The value of '%s' must not be a many-to-many field." % label, + "The value of '%s' must not be a ManyToManyField." % label, obj=obj.__class__, id='admin.E109', ) diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt index 03bdba97db..fce22689fe 100644 --- a/docs/ref/checks.txt +++ b/docs/ref/checks.txt @@ -302,7 +302,7 @@ with the admin site: ``fields``. * **admin.E012**: There are duplicate field(s) in ``fieldsets[n][1]``. * **admin.E013**: ``fields[n]/fieldsets[n][m]`` cannot include the - many-to-many field ````, because that field manually specifies a + ``ManyToManyField`` ````, because that field manually specifies a relationship model. * **admin.E014**: The value of ``exclude`` must be a list or tuple. * **admin.E015**: The value of ``exclude`` contains duplicate field(s). @@ -326,8 +326,8 @@ with the admin site: * **admin.E027**: The value of ``prepopulated_fields`` refers to ````, which is not an attribute of ````. * **admin.E028**: The value of ``prepopulated_fields`` refers to - ````, which must not be a ``DateTimeField``, a foreign key or a - many-to-many field. + ````, which must not be a ``DateTimeField``, a ``ForeignKey``, or a + ``ManyToManyField`` field. * **admin.E029**: The value of ``prepopulated_fields[]`` must be a list or tuple. * **admin.E030**: The value of ``prepopulated_fields`` refers to @@ -361,7 +361,7 @@ with the admin site: which is not a callable, an attribute of ````, or an attribute or method on ````. * **admin.E109**: The value of ``list_display[n]`` must not be a - many-to-many field. + ``ManyToManyField`` field. * **admin.E110**: The value of ``list_display_links`` must be a list, a tuple, or ``None``. * **admin.E111**: The value of ``list_display_links[n]`` refers to ``