Skip to content
Browse files

Improved model validator to validate 'choices' for a field

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 5607175 commit 7cfddb3c43ba5b006b0e0082dfc77abeb846a15a @adrianholovaty adrianholovaty committed
Showing with 7 additions and 0 deletions.
  1. +7 −0 django/core/
7 django/core/
@@ -506,6 +506,13 @@ def validate():
for f in opts.fields:
if isinstance(f, meta.CharField) and f.maxlength in (None, 0):
e.add(opts, '"%s" field: CharFields require a "maxlength" attribute.' %
+ if f.choices:
+ if not type(f.choices) in (tuple, list):
+ e.add(opts, '"%s" field: "choices" should be either a tuple or list.' %
+ else:
+ for c in f.choices:
+ if not type(c) in (tuple, list) or len(c) != 2:
+ e.add(opts, '"%s" field: "choices" should be a sequence of two-tuples.' %
# Check admin attribute.
if opts.admin is not None and not isinstance(opts.admin, meta.Admin):

0 comments on commit 7cfddb3

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