Hello,

currently you can add data to forms either by passing it into the
"initial" or the "data" argument of Form. However sometimes I have the
need to add data to a Form that isn't request.POST and doesn't come from
an http request.

My use case is the following:

I have a form where a user can edit a model. So I pass the current
values into "initial". Now the user can "save" his current changes
without saving the model instance. He can come back later and see the
changes he already made. So "initial" is still the data from the model
but now "data" has also be filled with the cached changes.
Only when the user clicks on "change model" the changes will actually be
made to the model.

The problem now is that when the user "saves" his intermediate changes I
get the data from form.cleaned_data and cache it somewhere. However if I
want to display the form back to the user I have to convert the data
from the format

{'field1': 'value1', 'field2': 'value2'}

into something like

{'form-prefix-widget-specific-field1': 'value1',
 'form-prefix-widget-specific-field2': 'value2'}

and have to actually know how the widgets get their data.

I'd like to propose a new argument to "django.forms.Form" called
"data_values".
Its semantics will be just like data. The difference is that it will be
a dictionary storing the data in {'field-name': 'field-value'} format
instead of a widget specific one.

I have a branch where I sketched this new functionality here:
https://github.com/MoritzS/django/tree/forms-data-values

I'd like to hear your comments on this!

Moritz

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/55F87E14.2090001%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: OpenPGP digital signature

  • I... 'Moritz Sichert' via Django developers (Contributions to Django itself)
    • ... Florian Apolloner
      • ... 'Moritz Sichert' via Django developers (Contributions to Django itself)
        • ... Yo-Yo Ma
          • ... 'Moritz Sichert' via Django developers (Contributions to Django itself)

Reply via email to