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.
--
Ticket URL: <https://code.djangoproject.com/ticket/26901>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Might be a duplicate of #14642. If not, could you please provide a test
for Django's test suite or a sample project to reproduce the issue?
--
Ticket URL: <https://code.djangoproject.com/ticket/26901#comment:1>
Comment (by eecp):
Indeed that looks very similar, sorry i missed that. My content_types_id
error is reproducable with the model of simon@... So we can close this
ticket. Still hope my patch lines may bring the topic a little forward.
--
Ticket URL: <https://code.djangoproject.com/ticket/26901#comment:2>
* status: new => closed
* resolution: => duplicate
--
Ticket URL: <https://code.djangoproject.com/ticket/26901#comment:3>