Skip to content

Commit

Permalink
Fixed #9882 -- Added alters_data = True to BaseModelForm.save met…
Browse files Browse the repository at this point in the history
…hod, thanks dc.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9678 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
gdub committed Dec 23, 2008
1 parent 7bf9626 commit f0d44e4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions django/forms/models.py
Expand Up @@ -56,10 +56,10 @@ def save_instance(form, instance, fields=None, fail_message='saved',
file_field_list.append(f)
else:
f.save_form_data(instance, cleaned_data[f.name])

for f in file_field_list:
f.save_form_data(instance, cleaned_data[f.name])

# Wrap up the saving of m2m data as a function.
def save_m2m():
opts = instance._meta
Expand Down Expand Up @@ -226,11 +226,11 @@ def clean(self):
def validate_unique(self):
from django.db.models.fields import FieldDoesNotExist

# 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
# ModelForm, some fields may have been excluded; we can't perform a unique
# 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
# ModelForm, some fields may have been excluded; we can't perform a unique
# check on a form that is missing fields involved in that check. It also does
# not make sense to check data that didn't validate, and since NULL does not
# not make sense to check data that didn't validate, and since NULL does not
# equal NULL in SQL we should not do any unique checking for NULL values.
unique_checks = []
for check in self.instance._meta.unique_together[:]:
Expand Down Expand Up @@ -318,6 +318,8 @@ def save(self, commit=True):
fail_message = 'changed'
return save_instance(self, self.instance, self._meta.fields, fail_message, commit)

save.alters_data = True

class ModelForm(BaseModelForm):
__metaclass__ = ModelFormMetaclass

Expand Down Expand Up @@ -480,7 +482,7 @@ def _construct_form(self, i, **kwargs):
# creating new instances
form.data[form.add_prefix(self._pk_field.name)] = None
return form

def save_new(self, form, commit=True):
fk_attname = self.fk.get_attname()
kwargs = {fk_attname: self.instance.pk}
Expand Down Expand Up @@ -585,7 +587,7 @@ class InlineForeignKeyField(Field):
default_error_messages = {
'invalid_choice': _(u'The inline foreign key did not match the parent instance primary key.'),
}

def __init__(self, parent_instance, *args, **kwargs):
self.parent_instance = parent_instance
self.pk_field = kwargs.pop("pk_field", False)
Expand All @@ -594,7 +596,7 @@ def __init__(self, parent_instance, *args, **kwargs):
kwargs["required"] = False
kwargs["widget"] = InlineForeignKeyHiddenInput
super(InlineForeignKeyField, self).__init__(*args, **kwargs)

def clean(self, value):
if value in EMPTY_VALUES:
if self.pk_field:
Expand Down

0 comments on commit f0d44e4

Please sign in to comment.