Kaydet (Commit) 021ba30a authored tarafından Karen Tracey's avatar Karen Tracey

Fixed #12481: Updated admin validation code to not reject non-editable fields in…

Fixed #12481: Updated admin validation code to not reject non-editable 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
üst f2bc4dd0
......@@ -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)
......
......@@ -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',)
......
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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment