Django

Code

Changeset 1513

Show
Ignore:
Timestamp:
11/30/05 23:46:18 (3 years ago)
Author:
adrian
Message:

Improved model validator to throw error if a model has two ManyToMany? relationships to the same model and doesn't set 'singular'. Refs #452.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management.py

    r1484 r1513  
    647647                                e.add(opts, '"%s" field: "choices" should be a sequence of two-tuples.' % f.name) 
    648648 
     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 
    649656            # Check admin attribute. 
    650657            if opts.admin is not None: