summaryrefslogtreecommitdiff
path: root/django/core/management.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-08-15 19:00:50 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-08-15 19:00:50 +0000
commit7cfddb3c43ba5b006b0e0082dfc77abeb846a15a (patch)
treefe3588b434355849a5adf757e8f2aab8ae1a02fa /django/core/management.py
parent56071754eafd264ccfeef7d0742c7482baed4dae (diff)
Improved model validator to validate 'choices' for a field
git-svn-id: http://code.djangoproject.com/svn/django/trunk@509 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/management.py')
-rw-r--r--django/core/management.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/core/management.py b/django/core/management.py
index 4a16d214ec..af6661fb8b 100644
--- a/django/core/management.py
+++ b/django/core/management.py
@@ -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.' % f.name)
+ if f.choices:
+ if not type(f.choices) in (tuple, list):
+ e.add(opts, '"%s" field: "choices" should be either a tuple or list.' % f.name)
+ 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.' % f.name)
# Check admin attribute.
if opts.admin is not None and not isinstance(opts.admin, meta.Admin):