Code

Ticket #7772: fields_and_fields.diff

File fields_and_fields.diff, 2.1 KB (added by julien, 6 years ago)

Patch + tests

Line 
1Index: django/django/contrib/admin/validation.py
2===================================================================
3--- django/django/contrib/admin/validation.py   (revision 7930)
4+++ django/django/contrib/admin/validation.py   (working copy)
5@@ -154,6 +154,8 @@
6         _check_istuplew('fields', cls.fields)
7         for field in cls.fields:
8             _check_field_existsw('fields', field)
9+        if cls.fieldsets:
10+            raise ImproperlyConfigured('Both fieldsets and fields are specified in %s.' % cls.__name__)
11 
12     # fieldsets
13     if cls.fieldsets: # default value is None
14Index: django/django/contrib/admin/options.py
15===================================================================
16--- django/django/contrib/admin/options.py      (revision 7930)
17+++ django/django/contrib/admin/options.py      (working copy)
18@@ -143,12 +143,6 @@
19     radio_fields = {}
20     prepopulated_fields = {}
21 
22-    def __init__(self):
23-        # TODO: This should really go in django.core.validation, but validation
24-        # doesn't work on ModelAdmin classes yet.
25-        if self.fieldsets and self.fields:
26-            raise ImproperlyConfigured('Both fieldsets and fields is specified for %s.' % self.model)
27-
28     def formfield_for_dbfield(self, db_field, **kwargs):
29         """
30         Hook for specifying the form Field instance for a given database Field
31Index: django/tests/regressiontests/modeladmin/models.py
32===================================================================
33--- django/tests/regressiontests/modeladmin/models.py   (revision 7930)
34+++ django/tests/regressiontests/modeladmin/models.py   (working copy)
35@@ -337,6 +337,14 @@
36 ...     fieldsets = (("General", {"fields": ("name",)}),)
37 >>> validate(ValidationTestModelAdmin, ValidationTestModel)
38 
39+>>> class ValidationTestModelAdmin(ModelAdmin):
40+...     fieldsets = (("General", {"fields": ("name",)}),)
41+...     fields = ["name",]
42+>>> validate(ValidationTestModelAdmin, ValidationTestModel)
43+Traceback (most recent call last):
44+...
45+ImproperlyConfigured: Both fieldsets and fields are specified in ValidationTestModelAdmin.
46+
47 # form
48 
49 >>> class FakeForm(object):