diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-12-01 05:46:18 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-12-01 05:46:18 +0000 |
| commit | 9e2eccc1ab06e831f586e002915c00d90206b59b (patch) | |
| tree | 57e7b9f8a74dcad26e71f92bddf50ffb1c868f0d | |
| parent | e0f0532305a132b1c13b87d57f3b26c1d5f2be16 (diff) | |
Improved model validator to throw error if a model has two ManyToMany relationships to the same model and doesn't set 'singular'. Refs #452.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1513 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/core/management.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/django/core/management.py b/django/core/management.py index 06c31abe13..e474072e83 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -646,6 +646,13 @@ def get_validation_errors(outfile): 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 for multiple ManyToManyFields to the same object, and + # verify "singular" is set in that case. + for i, f in enumerate(opts.many_to_many): + for previous_f in opts.many_to_many[:i]: + if f.rel.to == previous_f.rel.to and f.rel.singular == previous_f.rel.singular: + e.add(opts, 'The "%s" field requires a "singular" parameter, because the %s model has more than one ManyToManyField to the same model (%s).' % (f.name, opts.object_name, previous_f.rel.to.object_name)) + # Check admin attribute. if opts.admin is not None: if not isinstance(opts.admin, meta.Admin): |
