Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 9e2eccc1ab06e831f586e002915c00d90206b59b 1 parent e0f0532
Adrian Holovaty authored December 01, 2005

Showing 1 changed file with 7 additions and 0 deletions. Show diff stats Hide diff stats

  1. 7  django/core/management.py
7  django/core/management.py
@@ -646,6 +646,13 @@ def get_validation_errors(outfile):
646 646
                             if not type(c) in (tuple, list) or len(c) != 2:
647 647
                                 e.add(opts, '"%s" field: "choices" should be a sequence of two-tuples.' % f.name)
648 648
 
  649
+            # Check for multiple ManyToManyFields to the same object, and
  650
+            # verify "singular" is set in that case.
  651
+            for i, f in enumerate(opts.many_to_many):
  652
+                for previous_f in opts.many_to_many[:i]:
  653
+                    if f.rel.to == previous_f.rel.to and f.rel.singular == previous_f.rel.singular:
  654
+                        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))
  655
+
649 656
             # Check admin attribute.
650 657
             if opts.admin is not None:
651 658
                 if not isinstance(opts.admin, meta.Admin):

0 notes on commit 9e2eccc

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