diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2005-09-15 16:54:46 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2005-09-15 16:54:46 +0000 |
| commit | 526de4987a36d10312edeb5f342d8868928e475e (patch) | |
| tree | 407092967ccfabd8da745fa8ae6eb8eeefdec657 | |
| parent | 1874f26d2229deec85b851261b64f26fb969fe0f (diff) | |
Fixed "unique" validator for fields with relations.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@643 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/core/meta/fields.py | 6 |
1 files changed, 5 insertions, 1 deletions
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): |
