From 526de4987a36d10312edeb5f342d8868928e475e Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Thu, 15 Sep 2005 16:54:46 +0000 Subject: [PATCH] Fixed "unique" validator for fields with relations. git-svn-id: http://code.djangoproject.com/svn/django/trunk@643 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/meta/fields.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/django/core/meta/fields.py b/django/core/meta/fields.py index da201ef8f3..56ded6edd7 100644 --- a/django/core/meta/fields.py +++ b/django/core/meta/fields.py @@ -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):