1
0
mirror of https://github.com/django/django.git synced 2025-10-28 08:06:09 +00:00

Fixed #9865 -- Allow saving of new inline-edited objects with custom non-auto primary key fields that are not the foreign key to the parent object.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9664 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Karen Tracey
2008-12-21 04:56:32 +00:00
parent 04ed423469
commit ca33f07e2c
2 changed files with 43 additions and 2 deletions

View File

@@ -482,9 +482,14 @@ class BaseInlineFormSet(BaseModelFormSet):
return form
def save_new(self, form, commit=True):
kwargs = {self.fk.get_attname(): self.instance.pk}
fk_attname = self.fk.get_attname()
kwargs = {fk_attname: self.instance.pk}
new_obj = self.model(**kwargs)
return save_instance(form, new_obj, exclude=[self._pk_field.name], commit=commit)
if fk_attname == self._pk_field.attname:
exclude = [self._pk_field.name]
else:
exclude = []
return save_instance(form, new_obj, exclude=exclude, commit=commit)
def add_fields(self, form, index):
super(BaseInlineFormSet, self).add_fields(form, index)