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
This commit is contained in:
parent
f2bc4dd0a9
commit
021ba30ad1
|
@ -245,6 +245,12 @@ def validate_base(cls, model):
|
||||||
if type(fields) != tuple:
|
if type(fields) != tuple:
|
||||||
fields = (fields,)
|
fields = (fields,)
|
||||||
for field in 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)
|
check_formfield(cls, model, opts, "fieldsets[%d][1]['fields']" % idx, field)
|
||||||
try:
|
try:
|
||||||
f = opts.get_field(field)
|
f = opts.get_field(field)
|
||||||
|
|
|
@ -12,6 +12,7 @@ class Album(models.Model):
|
||||||
class Song(models.Model):
|
class Song(models.Model):
|
||||||
title = models.CharField(max_length=150)
|
title = models.CharField(max_length=150)
|
||||||
album = models.ForeignKey(Album)
|
album = models.ForeignKey(Album)
|
||||||
|
original_release = models.DateField(editable=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('title',)
|
ordering = ('title',)
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue