From 1e37cb37cec330a6b78925e2ef5589817428d09a Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Thu, 9 May 2013 15:11:02 +0100 Subject: [PATCH] Further removal of static admin validation that can fail erroneously --- django/contrib/admin/validation.py | 17 ----------------- tests/admin_validation/tests.py | 2 -- tests/modeladmin/tests.py | 21 --------------------- 3 files changed, 40 deletions(-) diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index 178df9d844..8d65f96cf1 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -246,7 +246,6 @@ def validate_fields_spec(cls, model, opts, flds, label): # readonly_fields will handle the validation of such # things. continue - check_formfield(cls, model, opts, label, field) try: f = opts.get_field(field) except models.FieldDoesNotExist: @@ -302,14 +301,6 @@ def validate_base(cls, model): # exclude if cls.exclude: # default value is None check_isseq(cls, 'exclude', cls.exclude) - for field in cls.exclude: - check_formfield(cls, model, opts, 'exclude', field) - try: - f = opts.get_field(field) - except models.FieldDoesNotExist: - # If we can't find a field on the model that matches, - # it could be an extra field on the form. - continue if len(cls.exclude) > len(set(cls.exclude)): raise ImproperlyConfigured('There are duplicate field(s) in %s.exclude' % cls.__name__) @@ -380,14 +371,6 @@ def get_field(cls, model, opts, label, field): raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s.%s'." % (cls.__name__, label, field, model._meta.app_label, model.__name__)) -def check_formfield(cls, model, opts, label, field): - if getattr(cls.form, 'base_fields', None): - try: - cls.form.base_fields[field] - except KeyError: - raise ImproperlyConfigured("'%s.%s' refers to field '%s' that " - "is missing from the form." % (cls.__name__, label, field)) - def fetch_attr(cls, model, opts, label, field): try: return opts.get_field(field) diff --git a/tests/admin_validation/tests.py b/tests/admin_validation/tests.py index 5329cc7e8c..6ce0ee7e03 100644 --- a/tests/admin_validation/tests.py +++ b/tests/admin_validation/tests.py @@ -269,8 +269,6 @@ class ValidationTestCase(TestCase): """ class SongForm(forms.ModelForm): extra_data = forms.CharField() - class Meta: - model = Song class FieldsOnFormOnlyAdmin(admin.ModelAdmin): form = SongForm diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py index a63984a8a9..bac8d30153 100644 --- a/tests/modeladmin/tests.py +++ b/tests/modeladmin/tests.py @@ -682,27 +682,6 @@ class ValidationTests(unittest.TestCase): validate(BandAdmin, Band) - class AdminBandForm(forms.ModelForm): - class Meta: - model = Band - - class BandAdmin(ModelAdmin): - form = AdminBandForm - - fieldsets = ( - ('Band', { - 'fields': ('non_existent_field',) - }), - ) - - six.assertRaisesRegex(self, - ImproperlyConfigured, - "'BandAdmin.fieldsets\[0]\[1\]\['fields'\]' refers to field 'non_existent_field' that is missing from the form.", - validate, - BandAdmin, - Band, - ) - class AdminBandForm(forms.ModelForm): delete = forms.BooleanField()