Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

BaseGenericInlineFormSet does not use form's save() method #11

Closed
wants to merge 1 commit into from

2 participants

@pablorecio

Saving a BaseGenericInlineFormSet through the form instead of the model directly. Same patch that attached on ticket https://code.djangoproject.com/ticket/16869

@alex
Collaborator

This could use a test, and probably a note in the documentation.

@pablorecio

Thanks for the tip, I'll try to add something more.

@pablorecio pablorecio closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 28, 2012
  1. @pablorecio
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 6 deletions.
  1. +5 −6 django/contrib/contenttypes/generic.py
View
11 django/contrib/contenttypes/generic.py
@@ -412,12 +412,11 @@ def get_default_prefix(cls):
def save_new(self, form, commit=True):
# Avoid a circular import.
from django.contrib.contenttypes.models import ContentType
- kwargs = {
- self.ct_field.get_attname(): ContentType.objects.get_for_model(self.instance).pk,
- self.ct_fk_field.get_attname(): self.instance.pk,
- }
- new_obj = self.model(**kwargs)
- return save_instance(form, new_obj, commit=commit)
+ 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)
def generic_inlineformset_factory(model, form=ModelForm,
formset=BaseGenericInlineFormSet,
Something went wrong with that request. Please try again.