Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Further removal of static admin validation that can fail erroneously

  • Loading branch information...
commit 1e37cb37cec330a6b78925e2ef5589817428d09a 1 parent 1906cb9
Luke Plant authored May 09, 2013
17  django/contrib/admin/validation.py
@@ -246,7 +246,6 @@ def validate_fields_spec(cls, model, opts, flds, label):
246 246
                 # readonly_fields will handle the validation of such
247 247
                 # things.
248 248
                 continue
249  
-            check_formfield(cls, model, opts, label, field)
250 249
             try:
251 250
                 f = opts.get_field(field)
252 251
             except models.FieldDoesNotExist:
@@ -302,14 +301,6 @@ def validate_base(cls, model):
302 301
     # exclude
303 302
     if cls.exclude: # default value is None
304 303
         check_isseq(cls, 'exclude', cls.exclude)
305  
-        for field in cls.exclude:
306  
-            check_formfield(cls, model, opts, 'exclude', field)
307  
-            try:
308  
-                f = opts.get_field(field)
309  
-            except models.FieldDoesNotExist:
310  
-                # If we can't find a field on the model that matches,
311  
-                # it could be an extra field on the form.
312  
-                continue
313 304
         if len(cls.exclude) > len(set(cls.exclude)):
314 305
             raise ImproperlyConfigured('There are duplicate field(s) in %s.exclude' % cls.__name__)
315 306
 
@@ -380,14 +371,6 @@ def get_field(cls, model, opts, label, field):
380 371
         raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s.%s'."
381 372
                 % (cls.__name__, label, field, model._meta.app_label, model.__name__))
382 373
 
383  
-def check_formfield(cls, model, opts, label, field):
384  
-    if getattr(cls.form, 'base_fields', None):
385  
-        try:
386  
-            cls.form.base_fields[field]
387  
-        except KeyError:
388  
-            raise ImproperlyConfigured("'%s.%s' refers to field '%s' that "
389  
-                "is missing from the form." % (cls.__name__, label, field))
390  
-
391 374
 def fetch_attr(cls, model, opts, label, field):
392 375
     try:
393 376
         return opts.get_field(field)
2  tests/admin_validation/tests.py
@@ -269,8 +269,6 @@ def test_non_model_fields(self):
269 269
         """
270 270
         class SongForm(forms.ModelForm):
271 271
             extra_data = forms.CharField()
272  
-            class Meta:
273  
-                model = Song
274 272
 
275 273
         class FieldsOnFormOnlyAdmin(admin.ModelAdmin):
276 274
             form = SongForm
21  tests/modeladmin/tests.py
@@ -683,27 +683,6 @@ class BandAdmin(ModelAdmin):
683 683
         validate(BandAdmin, Band)
684 684
 
685 685
         class AdminBandForm(forms.ModelForm):
686  
-            class Meta:
687  
-                model = Band
688  
-
689  
-        class BandAdmin(ModelAdmin):
690  
-            form = AdminBandForm
691  
-
692  
-            fieldsets = (
693  
-                ('Band', {
694  
-                    'fields': ('non_existent_field',)
695  
-                }),
696  
-            )
697  
-
698  
-        six.assertRaisesRegex(self,
699  
-            ImproperlyConfigured,
700  
-            "'BandAdmin.fieldsets\[0]\[1\]\['fields'\]' refers to field 'non_existent_field' that is missing from the form.",
701  
-            validate,
702  
-            BandAdmin,
703  
-            Band,
704  
-        )
705  
-
706  
-        class AdminBandForm(forms.ModelForm):
707 686
             delete = forms.BooleanField()
708 687
 
709 688
             class Meta:

0 notes on commit 1e37cb3

Please sign in to comment.
Something went wrong with that request. Please try again.