Commits

Anonymous committed 29ed229

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.

Comments (0)

Files changed (4)

     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

django/contrib/admin/options.py

     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

django/contrib/admin/validation.py

         _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

tests/regressiontests/modeladmin/models.py

 ...     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):