Corrected a regression in validation of admin fieldsets with nested definitions from r11744. Thanks to Davor Lučić for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11752 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2009-11-19 15:07:42 +00:00
parent 0880fe8be4
commit be9376d9ad
2 changed files with 27 additions and 13 deletions

View File

@ -219,7 +219,12 @@ def validate_base(cls, model):
raise ImproperlyConfigured("'fields' key is required in " raise ImproperlyConfigured("'fields' key is required in "
"%s.fieldsets[%d][1] field options dict." "%s.fieldsets[%d][1] field options dict."
% (cls.__name__, idx)) % (cls.__name__, idx))
for field in fieldset[1]['fields']: for fields in fieldset[1]['fields']:
# The entry in fields might be a tuple. If it is a standalone
# field, make it into a tuple to make processing easier.
if type(fields) != tuple:
fields = (fields,)
for field in fields:
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)

View File

@ -32,6 +32,8 @@ class Author(models.Model):
class Book(models.Model): class Book(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
subtitle = models.CharField(max_length=100)
price = models.FloatField()
authors = models.ManyToManyField(Author, through='AuthorsBooks') authors = models.ManyToManyField(Author, through='AuthorsBooks')
@ -131,6 +133,13 @@ Traceback (most recent call last):
... ...
ImproperlyConfigured: 'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model. ImproperlyConfigured: 'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.
>>> class NestedFieldsetAdmin(admin.ModelAdmin):
... fieldsets = (
... ('Main', {'fields': ('price', ('name', 'subtitle'))}),
... )
>>> validate(NestedFieldsetAdmin, Book)
# Regression test for #12209 -- If the explicitly provided through model # Regression test for #12209 -- If the explicitly provided through model
# is specified as a string, the admin should still be able use # is specified as a string, the admin should still be able use
# Model.m2m_field.through # Model.m2m_field.through