Opened 10 years ago
Closed 10 years ago
#24348 closed New feature (needsinfo)
Allow to pass on initial data to change form for existing objects (again).
Reported by: | slachinger | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | simon.lachinger@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The scenario is to redirect the user to the change_view to review changes to an existing object before saving. For this the data for the changed fields needs to be passed on via GET-Parameters. This still works for "add" but no longer works for "change".
This worked/existed until 1.6 but no longer works in 1.7. I suspect this is related to the introduction of ModelAdmin.get_changeform_initial_data() method and the cleanup/optimization that came with it.
Based on the code from 1.7.2 in django/contrib/admin/options.py:1414-1420:
Maybe call self.get_changeform_initial_data(request) for both change and add and pass on the object (or none for add)?
Code highlighting:
if add: initial = self.get_changeform_initial_data(request, obj=None) # <- /add so obj=None form = ModelForm(initial=initial) formsets, inline_instances = self._create_formsets(request, self.model(), change=False) else: initial = self.get_changeform_initial_data(request, obj=obj) # <- maybe add this line? form = ModelForm(instance=obj) formsets, inline_instances = self._create_formsets(request, obj, change=True)
The change in the method signature might break code overriding get_changeform_initial_data() though.
Change History (2)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|---|
Easy pickings: | unset |
comment:2 by , 10 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
I am not quite sure the use case you are describing. Can you provide step by step instructions to reproduce the behavior that no longer works or a test for Django's test suite that passes on 1.6, but fails in 1.7+?