﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26901	"enable ""save-as-new"" feature for GenericInlines / ContentTypes"	eecp	nobody	"Hope i haven't overlooked a related ticket. I'm using Django 1.9.7 with some models having generic relations. Normal use like add or change with having those models as generic inlines in the admin of other models work without problem. However enabling ""save_as"" produces an database exception (content_types_id should not be not null) on executing the save (which would actually be an add with initial data). I tracked down the issue up to the definitions in ""forms.py"" of contenttypes.

If one compares the __init__ of BaseGenericInlineFormSet with those of BaseInlineFormSet one finds that the save_as_new flag is not stored into self and later on there is no initial_form_count-method using this flag to return 0. This ultimately leads to the actual behaviour that the formset's save routine assumes that the freshly instantiated inline object seems to already exist in the database and therefore gets never assigned any content_types_id related to the ""parent object"". 

I made a patch on my system like this:
{{{
@@ -15,6 +15,7 @@
                  prefix=None, queryset=None, **kwargs):
         opts = self.model._meta
         self.instance = instance
+        self.save_as_new = save_as_new
         self.rel_name = '-'.join((
             opts.app_label, opts.model_name,
             self.ct_field.name, self.ct_fk_field.name,
@@ -35,14 +36,24 @@
             **kwargs
         )
 
+    def initial_form_count(self):
+        if self.save_as_new:
+            return 0
+        return super(BaseGenericInlineFormSet, self).initial_form_count()
+
}}}
As i'm no hardcore coder i assume that maybe there is more to it and this patch should only be considered as partial."	New feature	closed	contrib.contenttypes	1.9	Normal	duplicate	save_as_new		Unreviewed	0	0	0	0	0	0
