Fix #15126: Better error message when passing invalid options to ModelFo... #1000

Merged
merged 1 commit into from Apr 7, 2013

Projects

None yet

3 participants

@bmispelon
Member

...rm.Meta.

@jezdez jezdez commented on an outdated diff Apr 7, 2013
django/forms/models.py
@@ -187,6 +187,23 @@ def __init__(self, options=None):
self.exclude = getattr(options, 'exclude', None)
self.widgets = getattr(options, 'widgets', None)
+ def _validate(self, form_class):
@jezdez
jezdez Apr 7, 2013 Member

Please don't add a new private method, just do this check in __new__.

@jezdez jezdez and 1 other commented on an outdated diff Apr 7, 2013
tests/model_forms/tests.py
@@ -228,6 +229,22 @@ class Meta:
self.assertEqual(list(LimitFields.base_fields),
['url'])
+ def test_limit_inexistant_field(self):
+ expected_msg = 'Unknown field(s) (inexistant) specified for Category'
+ with self.assertRaisesMessage(FieldError, expected_msg):
+ class InvalidCategoryForm(forms.ModelForm):
+ class Meta:
+ model = Category
+ fields = ['inexistant']
@jezdez
jezdez Apr 7, 2013 Member

Let's call this non_existent, please.

@sebleblanc
sebleblanc Apr 7, 2013

Why the underscore? "Nonexistent" is a legitimate word according to the Collins English Dictionary.

@jezdez
jezdez Apr 7, 2013 Member

I don't care about the underscore, only about the non-existence of the word "inexistant".

@jezdez jezdez merged commit b5c0b3d into django:master Apr 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment