Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #12481: Updated admin validation code to not reject non-editabl…

…e fields in readonly_fields, since these are handled fine by the display code itself. Thanks lashni and Alex.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12730 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 021ba30ad1d4fffada4f2d43d47a4704bcfca45e 1 parent f2bc4dd
@kmtracey kmtracey authored
View
6 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)
View
1  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',)
View
18 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)
Please sign in to comment.
Something went wrong with that request. Please try again.