summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-04-27 15:05:38 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-04-27 15:05:38 +0000
commitdd07c235454baea0c74fa373cc07187942f3aed0 (patch)
treef0cc411a11bdca546d16b7c78921a9511e66410a /django/forms
parentb031fa2376f489406b44f0dabed18b5d318c2e83 (diff)
Fixed #12749 -- Corrected a problem with validation of inline primary keys. Thanks to Chris.Wesseling@cwi.nl for the report, and nessita for the test case.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13034 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/models.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index 4ac3f950ba..a0ef2de67f 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -316,12 +316,23 @@ class BaseModelForm(BaseForm):
return self.cleaned_data
def _post_clean(self):
- exclude = self._get_validation_exclusions()
opts = self._meta
-
# Update the model instance with self.cleaned_data.
self.instance = construct_instance(self, self.instance, opts.fields, opts.exclude)
+ exclude = self._get_validation_exclusions()
+
+ # Foreign Keys being used to represent inline relationships
+ # are excluded from basic field value validation. This is for two
+ # reasons: firstly, the value may not be supplied (#12507; the
+ # case of providing new values to the admin); secondly the
+ # object being referred to may not yet fully exist (#12749).
+ # However, these fields *must* be included in uniqueness checks,
+ # so this can't be part of _get_validation_exclusions().
+ for f_name, field in self.fields.items():
+ if isinstance(field, InlineForeignKeyField):
+ exclude.append(f_name)
+
# Clean the model instance's fields.
try:
self.instance.clean_fields(exclude=exclude)
@@ -762,6 +773,7 @@ class BaseInlineFormSet(BaseModelFormSet):
unique_check = [field for field in unique_check if field != self.fk.name]
return super(BaseInlineFormSet, self).get_unique_error_message(unique_check)
+
def _get_foreign_key(parent_model, model, fk_name=None, can_fail=False):
"""
Finds and returns the ForeignKey from model to parent if there is one