Fixed #26998 -- Reverted some admin checks from checking field.many_to_many back to isinstance(field, models.ManyToManyField).

This partially reverts 983c158da7
This commit is contained in:
Collin Anderson 2016-08-18 12:45:27 -04:00 committed by Tim Graham
parent a3db480393
commit 384f89f8f8
5 changed files with 20 additions and 15 deletions

View File

@ -217,10 +217,11 @@ class BaseModelAdminChecks(object):
# be an extra field on the form. # be an extra field on the form.
return [] return []
else: 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 [ return [
checks.Error( 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." "because that field manually specifies a relationship model."
% (label, field_name), % (label, field_name),
obj=obj.__class__, obj=obj.__class__,
@ -393,11 +394,11 @@ class BaseModelAdminChecks(object):
return refer_to_missing_field(field=field_name, option=label, return refer_to_missing_field(field=field_name, option=label,
model=model, obj=obj, id='admin.E027') model=model, obj=obj, id='admin.E027')
else: else:
if field.many_to_many or isinstance(field, (models.DateTimeField, models.ForeignKey)): if isinstance(field, (models.DateTimeField, models.ForeignKey, models.ManyToManyField)):
return [ return [
checks.Error( checks.Error(
"The value of '%s' refers to '%s', which must not be a DateTimeField, " "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__, obj=obj.__class__,
id='admin.E028', id='admin.E028',
) )
@ -621,10 +622,10 @@ class ModelAdminChecks(BaseModelAdminChecks):
id='admin.E108', id='admin.E108',
) )
] ]
elif getattr(field, 'many_to_many', False): elif isinstance(field, models.ManyToManyField):
return [ return [
checks.Error( 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__, obj=obj.__class__,
id='admin.E109', id='admin.E109',
) )

View File

@ -312,7 +312,7 @@ with the admin site:
``fields``. ``fields``.
* **admin.E012**: There are duplicate field(s) in ``fieldsets[n][1]``. * **admin.E012**: There are duplicate field(s) in ``fieldsets[n][1]``.
* **admin.E013**: ``fields[n]/fieldsets[n][m]`` cannot include the * **admin.E013**: ``fields[n]/fieldsets[n][m]`` cannot include the
many-to-many field ``<field name>``, because that field manually specifies a ``ManyToManyField`` ``<field name>``, because that field manually specifies a
relationship model. relationship model.
* **admin.E014**: The value of ``exclude`` must be a list or tuple. * **admin.E014**: The value of ``exclude`` must be a list or tuple.
* **admin.E015**: The value of ``exclude`` contains duplicate field(s). * **admin.E015**: The value of ``exclude`` contains duplicate field(s).
@ -336,8 +336,8 @@ with the admin site:
* **admin.E027**: The value of ``prepopulated_fields`` refers to * **admin.E027**: The value of ``prepopulated_fields`` refers to
``<field name>``, which is not an attribute of ``<model>``. ``<field name>``, which is not an attribute of ``<model>``.
* **admin.E028**: The value of ``prepopulated_fields`` refers to * **admin.E028**: The value of ``prepopulated_fields`` refers to
``<field name>``, which must not be a ``DateTimeField``, a foreign key or a ``<field name>``, which must not be a ``DateTimeField``, a ``ForeignKey``, or a
many-to-many field. ``ManyToManyField`` field.
* **admin.E029**: The value of ``prepopulated_fields[<field name>]`` must be a * **admin.E029**: The value of ``prepopulated_fields[<field name>]`` must be a
list or tuple. list or tuple.
* **admin.E030**: The value of ``prepopulated_fields`` refers to * **admin.E030**: The value of ``prepopulated_fields`` refers to
@ -371,7 +371,7 @@ with the admin site:
which is not a callable, an attribute of ``<ModelAdmin class>``, or an which is not a callable, an attribute of ``<ModelAdmin class>``, or an
attribute or method on ``<model>``. attribute or method on ``<model>``.
* **admin.E109**: The value of ``list_display[n]`` must not be a * **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, * **admin.E110**: The value of ``list_display_links`` must be a list, a tuple,
or ``None``. or ``None``.
* **admin.E111**: The value of ``list_display_links[n]`` refers to ``<label>``, * **admin.E111**: The value of ``list_display_links[n]`` refers to ``<label>``,

View File

@ -61,3 +61,7 @@ Bugfixes
* Fixed ``contrib.admindocs`` crash when a view is in a class, such as some of * Fixed ``contrib.admindocs`` crash when a view is in a class, such as some of
the admin views (:ticket:`27018`). the admin views (:ticket:`27018`).
* Reverted a few admin checks that checked ``field.many_to_many`` back to
``isinstance(field, models.ManyToManyField)`` since it turned out the checks
weren't suitable to be generalized like that (:ticket:`26998`).

View File

@ -583,7 +583,7 @@ class SystemChecksTestCase(SimpleTestCase):
errors = BookAdmin(Book, AdminSite()).check() errors = BookAdmin(Book, AdminSite()).check()
expected = [ expected = [
checks.Error( checks.Error(
"The value of 'fields' cannot include the many-to-many field 'authors' " "The value of 'fields' cannot include the ManyToManyField 'authors', "
"because that field manually specifies a relationship model.", "because that field manually specifies a relationship model.",
obj=BookAdmin, obj=BookAdmin,
id='admin.E013', id='admin.E013',
@ -601,8 +601,8 @@ class SystemChecksTestCase(SimpleTestCase):
errors = FieldsetBookAdmin(Book, AdminSite()).check() errors = FieldsetBookAdmin(Book, AdminSite()).check()
expected = [ expected = [
checks.Error( checks.Error(
"The value of 'fieldsets[1][1][\"fields\"]' cannot include the many-to-many field " "The value of 'fieldsets[1][1][\"fields\"]' cannot include the ManyToManyField "
"'authors' because that field manually specifies a relationship model.", "'authors', because that field manually specifies a relationship model.",
obj=FieldsetBookAdmin, obj=FieldsetBookAdmin,
id='admin.E013', id='admin.E013',
) )

View File

@ -925,7 +925,7 @@ class PrepopulatedFieldsCheckTests(CheckTestCase):
self.assertIsInvalid( self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel, ValidationTestModelAdmin, ValidationTestModel,
("The value of 'prepopulated_fields' refers to 'users', which must not be " ("The value of 'prepopulated_fields' refers to 'users', which must not be "
"a DateTimeField, a foreign key, or a many-to-many field."), "a DateTimeField, a ForeignKey, or a ManyToManyField."),
'admin.E028') 'admin.E028')
def test_valid_case(self): def test_valid_case(self):
@ -963,7 +963,7 @@ class ListDisplayTests(CheckTestCase):
self.assertIsInvalid( self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel, ValidationTestModelAdmin, ValidationTestModel,
"The value of 'list_display[0]' must not be a many-to-many field.", "The value of 'list_display[0]' must not be a ManyToManyField.",
'admin.E109') 'admin.E109')
def test_valid_case(self): def test_valid_case(self):