mirror of https://github.com/django/django.git
Fixed #32494 -- Adjusted system check for raw_id_fields to warn about Field.attname.
This commit is contained in:
parent
1da54bfe7d
commit
20ddc3b81d
|
@ -239,6 +239,14 @@ class BaseModelAdminChecks:
|
|||
except FieldDoesNotExist:
|
||||
return refer_to_missing_field(field=field_name, option=label, obj=obj, id='admin.E002')
|
||||
else:
|
||||
# Using attname is not supported.
|
||||
if field.name != field_name:
|
||||
return refer_to_missing_field(
|
||||
field=field_name,
|
||||
option=label,
|
||||
obj=obj,
|
||||
id='admin.E002',
|
||||
)
|
||||
if not field.many_to_many and not isinstance(field, models.ForeignKey):
|
||||
return must_be('a foreign key or a many-to-many field', option=label, obj=obj, id='admin.E003')
|
||||
else:
|
||||
|
|
|
@ -84,6 +84,18 @@ class RawIdCheckTests(CheckTestCase):
|
|||
|
||||
self.assertIsValid(TestModelAdmin, ValidationTestModel)
|
||||
|
||||
def test_field_attname(self):
|
||||
class TestModelAdmin(ModelAdmin):
|
||||
raw_id_fields = ['band_id']
|
||||
|
||||
self.assertIsInvalid(
|
||||
TestModelAdmin,
|
||||
ValidationTestModel,
|
||||
"The value of 'raw_id_fields[0]' refers to 'band_id', which is "
|
||||
"not a field of 'modeladmin.ValidationTestModel'.",
|
||||
'admin.E002',
|
||||
)
|
||||
|
||||
|
||||
class FieldsetsCheckTests(CheckTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue