Django

Code

Changeset 643

Show
Ignore:
Timestamp:
09/15/05 11:54:46 (3 years ago)
Author:
jacob
Message:

Fixed "unique" validator for fields with relations.

Files:

Legend:

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

    r549 r643  
    3737def manipulator_validator_unique(f, opts, self, field_data, all_data): 
    3838    "Validates that the value is unique for this field." 
     39    if f.rel and isinstance(f.rel, ManyToOne): 
     40        lookup_type = 'pk' 
     41    else: 
     42        lookup_type = 'exact' 
    3943    try: 
    40         old_obj = opts.get_model_module().get_object(**{'%s__exact' % f.name: field_data}) 
     44        old_obj = opts.get_model_module().get_object(**{'%s__%s' % (f.name, lookup_type): field_data}) 
    4145    except ObjectDoesNotExist: 
    4246        return