Fixed "unique" validator for fields with relations.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@643 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1874f26d22
commit
526de4987a
|
@ -36,8 +36,12 @@ def manipulator_valid_rel_key(f, self, field_data, all_data):
|
|||
|
||||
def manipulator_validator_unique(f, opts, self, field_data, all_data):
|
||||
"Validates that the value is unique for this field."
|
||||
if f.rel and isinstance(f.rel, ManyToOne):
|
||||
lookup_type = 'pk'
|
||||
else:
|
||||
lookup_type = 'exact'
|
||||
try:
|
||||
old_obj = opts.get_model_module().get_object(**{'%s__exact' % f.name: field_data})
|
||||
old_obj = opts.get_model_module().get_object(**{'%s__%s' % (f.name, lookup_type): field_data})
|
||||
except ObjectDoesNotExist:
|
||||
return
|
||||
if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.column) == getattr(old_obj, opts.pk.column):
|
||||
|
|
Loading…
Reference in New Issue