Opened 10 years ago
Last modified 10 years ago
#24348 closed New feature
Allow to pass on initial data to change form for existing objects (again). — at Initial Version
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
The szenario is to redirect the user to the change_view to review changes to an existing object bevore 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.