Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed "unique" validator for fields with relations.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@643 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 526de4987a36d10312edeb5f342d8868928e475e 1 parent 1874f26
Jacob Kaplan-Moss jacobian authored
Showing with 5 additions and 1 deletion.
  1. +5 −1 django/core/meta/fields.py
6 django/core/meta/fields.py
View
@@ -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):
Please sign in to comment.
Something went wrong with that request. Please try again.