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:
Jacob Kaplan-Moss 2005-09-15 16:54:46 +00:00
parent 1874f26d22
commit 526de4987a
1 changed files with 5 additions and 1 deletions

View File

@ -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): def manipulator_validator_unique(f, opts, self, field_data, all_data):
"Validates that the value is unique for this field." "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: 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: except ObjectDoesNotExist:
return return
if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.column) == getattr(old_obj, opts.pk.column): if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.column) == getattr(old_obj, opts.pk.column):