Code

Ticket #12577: inline.diff

File inline.diff, 983 bytes (added by raffaele.salmaso@…, 4 years ago)

reenable the save_new in BaseGenericInlineFormSet

Line 
1diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
2--- a/django/contrib/contenttypes/generic.py
3+++ b/django/contrib/contenttypes/generic.py
4@@ -342,6 +342,16 @@
5         setattr(form.instance, self.ct_field.attname, ContentType.objects.get_for_model(self.instance).pk)
6         return form
7 
8+    def save_new(self, form, commit=True):
9+        # Avoid a circular import.
10+        from django.contrib.contenttypes.models import ContentType
11+        kwargs = {
12+            self.ct_field.get_attname(): ContentType.objects.get_for_model(self.instance).pk,
13+            self.ct_fk_field.get_attname(): self.instance.pk,
14+        }
15+        new_obj = self.model(**kwargs)
16+        return save_instance(form, new_obj, commit=commit)
17+
18 def generic_inlineformset_factory(model, form=ModelForm,
19                                   formset=BaseGenericInlineFormSet,
20                                   ct_field="content_type", fk_field="object_id",