Further removal of static admin validation that can fail erroneously
This commit is contained in:
parent
1906cb9360
commit
1e37cb37ce
|
@ -246,7 +246,6 @@ def validate_fields_spec(cls, model, opts, flds, label):
|
||||||
# readonly_fields will handle the validation of such
|
# readonly_fields will handle the validation of such
|
||||||
# things.
|
# things.
|
||||||
continue
|
continue
|
||||||
check_formfield(cls, model, opts, label, field)
|
|
||||||
try:
|
try:
|
||||||
f = opts.get_field(field)
|
f = opts.get_field(field)
|
||||||
except models.FieldDoesNotExist:
|
except models.FieldDoesNotExist:
|
||||||
|
@ -302,14 +301,6 @@ def validate_base(cls, model):
|
||||||
# exclude
|
# exclude
|
||||||
if cls.exclude: # default value is None
|
if cls.exclude: # default value is None
|
||||||
check_isseq(cls, 'exclude', cls.exclude)
|
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)):
|
if len(cls.exclude) > len(set(cls.exclude)):
|
||||||
raise ImproperlyConfigured('There are duplicate field(s) in %s.exclude' % cls.__name__)
|
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'."
|
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__))
|
% (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):
|
def fetch_attr(cls, model, opts, label, field):
|
||||||
try:
|
try:
|
||||||
return opts.get_field(field)
|
return opts.get_field(field)
|
||||||
|
|
|
@ -269,8 +269,6 @@ class ValidationTestCase(TestCase):
|
||||||
"""
|
"""
|
||||||
class SongForm(forms.ModelForm):
|
class SongForm(forms.ModelForm):
|
||||||
extra_data = forms.CharField()
|
extra_data = forms.CharField()
|
||||||
class Meta:
|
|
||||||
model = Song
|
|
||||||
|
|
||||||
class FieldsOnFormOnlyAdmin(admin.ModelAdmin):
|
class FieldsOnFormOnlyAdmin(admin.ModelAdmin):
|
||||||
form = SongForm
|
form = SongForm
|
||||||
|
|
|
@ -682,27 +682,6 @@ class ValidationTests(unittest.TestCase):
|
||||||
|
|
||||||
validate(BandAdmin, Band)
|
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):
|
class AdminBandForm(forms.ModelForm):
|
||||||
delete = forms.BooleanField()
|
delete = forms.BooleanField()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue