diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index 94d4bbd9ce..f743f2c6c7 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -245,6 +245,12 @@ def validate_base(cls, model): if type(fields) != tuple: fields = (fields,) for field in fields: + if field in cls.readonly_fields: + # Stuff can be put in fields that isn't actually a + # model field if it's in readonly_fields, + # readonly_fields will handle the validation of such + # things. + continue check_formfield(cls, model, opts, "fieldsets[%d][1]['fields']" % idx, field) try: f = opts.get_field(field) diff --git a/tests/regressiontests/admin_validation/models.py b/tests/regressiontests/admin_validation/models.py index ef65c45352..b50764844e 100644 --- a/tests/regressiontests/admin_validation/models.py +++ b/tests/regressiontests/admin_validation/models.py @@ -12,6 +12,7 @@ class Album(models.Model): class Song(models.Model): title = models.CharField(max_length=150) album = models.ForeignKey(Album) + original_release = models.DateField(editable=False) class Meta: ordering = ('title',) diff --git a/tests/regressiontests/admin_validation/tests.py b/tests/regressiontests/admin_validation/tests.py new file mode 100644 index 0000000000..9166360ae3 --- /dev/null +++ b/tests/regressiontests/admin_validation/tests.py @@ -0,0 +1,18 @@ +from django.contrib import admin +from django.contrib.admin.validation import validate +from django.test import TestCase + +from models import Song + + +class ValidationTestCase(TestCase): + def test_readonly_and_editable(self): + class SongAdmin(admin.ModelAdmin): + readonly_fields = ["original_release"] + fieldsets = [ + (None, { + "fields": ["title", "original_release"], + }), + ] + + validate(SongAdmin, Song)