diff options
| author | Baptiste Mispelon <bmispelon@gmail.com> | 2013-04-07 18:41:35 +0200 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2013-04-07 19:08:53 +0200 |
| commit | f9dc1379b874f80694a80e95f0f266a3d42f7368 (patch) | |
| tree | b11ff5802383cfe41eb6c344df6d8ca704b7a8eb /django/forms | |
| parent | 5ab66dea50eab6625e3a07b71342268432e9cfaf (diff) | |
Fix #15126: Better error message when passing invalid options to ModelForm.Meta.
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/models.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index 5185e17c32..6a4b8b80e4 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -205,6 +205,21 @@ class ModelFormMetaclass(type): if 'media' not in attrs: new_class.media = media_property(new_class) opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None)) + + # We check if a string was passed to `fields` or `exclude`, + # which is likely to be a mistake where the user typed ('foo') instead + # of ('foo',) + for opt in ['fields', 'exclude']: + value = getattr(opts, opt) + if isinstance(value, six.string_types): + msg = ("%(model)s.Meta.%(opt)s cannot be a string. " + "Did you mean to type: ('%(value)s',)?" % { + 'model': new_class.__name__, + 'opt': opt, + 'value': value, + }) + raise TypeError(msg) + if opts.model: # If a model is defined, extract form fields from it. fields = fields_for_model(opts.model, opts.fields, |
