[Django] #26901: enable "save-as-new" feature for GenericInlines / ContentTypes

17 views
Skip to first unread message

Django

unread,
Jul 16, 2016, 5:08:57 AM7/16/16
to django-...@googlegroups.com
#26901: enable "save-as-new" feature for GenericInlines / ContentTypes
--------------------------------------+-------------------------
Reporter: eecp | Owner: nobody
Type: New feature | Status: new
Component: contrib.contenttypes | Version: 1.9
Severity: Normal | Keywords: save_as_new
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+-------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26901>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 16, 2016, 8:33:37 AM7/16/16
to django-...@googlegroups.com
#26901: enable "save-as-new" feature for GenericInlines / ContentTypes
-------------------------------------+-------------------------------------

Reporter: eecp | Owner: nobody
Type: New feature | Status: new
Component: | Version: 1.9
contrib.contenttypes |
Severity: Normal | Resolution:

Keywords: save_as_new | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Jul 16, 2016, 5:19:31 PM7/16/16
to django-...@googlegroups.com
#26901: enable "save-as-new" feature for GenericInlines / ContentTypes
-------------------------------------+-------------------------------------

Reporter: eecp | Owner: nobody
Type: New feature | Status: new
Component: | Version: 1.9
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: save_as_new | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jul 16, 2016, 8:01:32 PM7/16/16
to django-...@googlegroups.com
#26901: enable "save-as-new" feature for GenericInlines / ContentTypes
-------------------------------------+-------------------------------------
Reporter: eecp | Owner: nobody
Type: New feature | Status: closed
Component: | Version: 1.9
contrib.contenttypes |
Severity: Normal | Resolution: duplicate

Keywords: save_as_new | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => duplicate


--
Ticket URL: <https://code.djangoproject.com/ticket/26901#comment:3>

Reply all
Reply to author
Forward
0 new messages