Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Karen Tracey authored
6  django/contrib/admin/validation.py
@@ -245,6 +245,12 @@ def validate_base(cls, model):
245 245
                 if type(fields) != tuple:
246 246
                     fields = (fields,)
247 247
                 for field in fields:
  248
+                    if field in cls.readonly_fields:
  249
+                        # Stuff can be put in fields that isn't actually a
  250
+                        # model field if it's in readonly_fields,
  251
+                        # readonly_fields will handle the validation of such
  252
+                        # things.
  253
+                        continue
248 254
                     check_formfield(cls, model, opts, "fieldsets[%d][1]['fields']" % idx, field)
249 255
                     try:
250 256
                         f = opts.get_field(field)
1  tests/regressiontests/admin_validation/models.py
@@ -12,6 +12,7 @@ class Album(models.Model):
12 12
 class Song(models.Model):
13 13
     title = models.CharField(max_length=150)
14 14
     album = models.ForeignKey(Album)
  15
+    original_release = models.DateField(editable=False)
15 16
 
16 17
     class Meta:
17 18
         ordering = ('title',)
18  tests/regressiontests/admin_validation/tests.py
... ...
@@ -0,0 +1,18 @@
  1
+from django.contrib import admin
  2
+from django.contrib.admin.validation import validate
  3
+from django.test import TestCase
  4
+
  5
+from models import Song
  6
+
  7
+
  8
+class ValidationTestCase(TestCase):
  9
+    def test_readonly_and_editable(self):
  10
+        class SongAdmin(admin.ModelAdmin):
  11
+            readonly_fields = ["original_release"]
  12
+            fieldsets = [
  13
+                (None, {
  14
+                    "fields": ["title", "original_release"],
  15
+                }),
  16
+            ]
  17
+        
  18
+        validate(SongAdmin, Song)

0 notes on commit 021ba30

Please sign in to comment.
Something went wrong with that request. Please try again.