1
0
mirror of https://github.com/django/django.git synced 2025-07-03 09:19:16 +00:00

newforms-admin: Fixed #7772 -- Moved the validation check for when both fields and fieldsets are specified on a ModelAdmin to django/contrib/admin/validation.py. Thanks Julien Phalip for catching this.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7932 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Brian Rosner 2008-07-16 02:01:18 +00:00
parent 5317864e5f
commit 83afd39b1a
4 changed files with 11 additions and 6 deletions

View File

@ -297,6 +297,7 @@ answer newbie questions, and generally made Django that much better:
peter@mymart.com
pgross@thoughtworks.com
phaedo <http://phaedo.cx/>
Julien Phalip <http://www.julienphalip.com>
phil@produxion.net
phil.h.smith@gmail.com
Gustavo Picon

View File

@ -143,12 +143,6 @@ class BaseModelAdmin(object):
radio_fields = {}
prepopulated_fields = {}
def __init__(self):
# TODO: This should really go in django.core.validation, but validation
# doesn't work on ModelAdmin classes yet.
if self.fieldsets and self.fields:
raise ImproperlyConfigured('Both fieldsets and fields is specified for %s.' % self.model)
def formfield_for_dbfield(self, db_field, **kwargs):
"""
Hook for specifying the form Field instance for a given database Field

View File

@ -160,6 +160,8 @@ def _validate_base(cls, model):
_check_istuplew('fields', cls.fields)
for field in cls.fields:
_check_field_existsw('fields', field)
if cls.fieldsets:
raise ImproperlyConfigured('Both fieldsets and fields are specified in %s.' % cls.__name__)
# fieldsets
if cls.fieldsets: # default value is None

View File

@ -338,6 +338,14 @@ ImproperlyConfigured: `ValidationTestModelAdmin.fieldsets[0][1]['fields']` refer
... fieldsets = (("General", {"fields": ("name",)}),)
>>> validate(ValidationTestModelAdmin, ValidationTestModel)
>>> class ValidationTestModelAdmin(ModelAdmin):
... fieldsets = (("General", {"fields": ("name",)}),)
... fields = ["name",]
>>> validate(ValidationTestModelAdmin, ValidationTestModel)
Traceback (most recent call last):
...
ImproperlyConfigured: Both fieldsets and fields are specified in ValidationTestModelAdmin.
# form
>>> class FakeForm(object):