#24348: Allow to pass on initial data to change form for existing objects 
(again).
-------------------------------+--------------------------------------
     Reporter:  slachinger     |                    Owner:  nobody
         Type:  New feature    |                   Status:  new
    Component:  contrib.admin  |                  Version:  1.7
     Severity:  Normal         |               Resolution:
     Keywords:                 |             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_docs:   => 0
 * easy:  1 => 0
 * needs_tests:   => 0
 * needs_better_patch:   => 0


Old 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)?
> {{{
> #!div style="font-size: 80%"
> Code highlighting:
>   {{{#!python
>             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.

New description:

 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)?
 {{{
 #!div style="font-size: 80%"
 Code highlighting:
   {{{#!python
             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.

--

Comment:

 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+?

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.7353d119d49decb5663f989a8d9d36a7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to