Opened 13 years ago

Closed 11 years ago

Last modified 11 years ago

#16869 closed Bug (fixed)

BaseGenericInlineFormSet does not use form's save() method

Reported by: Matt Austin Owned by: pyriku
Component: contrib.contenttypes Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Changeset [12268] introduced the save_new() method on BaseGenericInlineFormSet - however this uses creates a new object based on self.model and thehn uses save_instance(), bypassing any custom code on the form's save() method.

Would the following not provide the same functionality and honor the form's save() method?

    def save_new(self, form, commit=True):
        setattr(form.instance, self.ct_field.get_attname(),
            ContentType.objects.get_for_model(self.instance).pk)
        setattr(form.instance, self.ct_fk_field.get_attname(),
            self.instance.pk)
        return form.save(commit=commit)

Attachments (1)

save_new_using_form_save.patch (1.1 KB ) - added by pyriku 13 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by pyriku, 13 years ago

Owner: changed from nobody to pyriku

by pyriku, 13 years ago

comment:2 by pyriku, 13 years ago

Has patch: set

Attached the patch as described.

comment:3 by pyriku, 13 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Ramiro Morales, 12 years ago

Needs documentation: set
Needs tests: set

comment:5 by polmuz, 11 years ago

Needs documentation: unset
Needs tests: unset

I added a test for the patch provided by pyriku and created a pull request with it. https://github.com/django/django/pull/1599

comment:6 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In b11564fd36587b1077bf7d77b62b7879cc08c382:

Fixed #16869 -- BaseGenericInlineFormSet.save_new should use form's save() method

Thanks mattaustin for the report and Pablo Recio (pyriku) for the patch.

comment:7 by Matt Austin, 11 years ago

Thanks for the patch/commit. Any chance of this being cherry-picked to Django 1.6, or are we too late?

Note: See TracTickets for help on using tickets.
Back to Top