summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2009-01-19 19:43:01 +0000
committerKaren Tracey <kmtracey@gmail.com>2009-01-19 19:43:01 +0000
commit709476ae0574ee19d35640c03770377cfca6d91d (patch)
treeb149fde159dd85275bb72f406931fc37e601d1be /django
parent3e19109ab61f851683d9a6427a52b4866071fa60 (diff)
[1.0.X] Fixed #10069 -- Fixed the model form unique validation code to not proceed with using, for example, RelatedObjects returned by get_field_by_name as though they were model Fields.
r9777 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9778 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/forms/models.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index 03ad10a4ea..01bd912063 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -224,7 +224,7 @@ class BaseModelForm(BaseForm):
return self.cleaned_data
def validate_unique(self):
- from django.db.models.fields import FieldDoesNotExist
+ from django.db.models.fields import FieldDoesNotExist, Field as ModelField
# Gather a list of checks to perform. We only perform unique checks
# for fields present and not None in cleaned_data. Since this is a
@@ -248,6 +248,12 @@ class BaseModelForm(BaseForm):
except FieldDoesNotExist:
# This is an extra field that's not on the ModelForm, ignore it
continue
+ if not isinstance(f, ModelField):
+ # This is an extra field that happens to have a name that matches,
+ # for example, a related object accessor for this model. So
+ # get_field_by_name found it, but it is not a Field so do not proceed
+ # to use it as if it were.
+ continue
if f.unique and self.cleaned_data.get(name) is not None:
unique_checks.append((name,))