In one of my forms I've declared a MultipleHiddenInput(), like this:

        self.fields['tiles'].widget = forms.MultipleHiddenInput()

In my model, tiles is a manyToMany field.  When I get the POST from
this form, I find that the has_changed() function returns true for the
form due to this 'tiles' field, even though it hasn't changed.  When I
look at the code, in forms.py I see this:

                if not field.show_hidden_initial:
                    initial_value = self.initial.get(name,
field.initial)
                else:
                    initial_prefixed_name = self.add_initial_prefix
(name)
                    hidden_widget = field.hidden_widget()
                    initial_value = hidden_widget.value_from_datadict(
                        self.data, self.files, initial_prefixed_name)
                if field.widget._has_changed(initial_value,
data_value):
                    self._changed_data.append(name)


and I find I am falling into the if.  Then when the if in the second
to last line executes:

                if field.widget._has_changed(initial_value,
data_value):

I find that the values are set like this:

(Pdb) initial_value
[1]
(Pdb) data_value
[u'1']

but has_changed() now returns True.

Malcolm or anyone ... do you have any pointers for me?  The reason I
am sending this data out in the first place as hidden data is that I'm
using formsets and in order to be able to leverage the utility of
formset->save() to save out my objects, it seems necessary to have the
required data in the form.  Thus, I send it out with the form and then
get it back in the POST, which allows me to save the formset to the
underlying object.

This was all working fine when I displayed the fields to the user.
But now that I am trying to hide this ManyToMany field via a
hiddeninput, I find that the form is comign back as "changed" when it
didn't otherwise.

Anyway, haven't had time to fully debug this but am wondering if
anyone has any pointers for me on what this show_hidden_initial
attribute is, if it is relevant here, and if it should be set to 1 in
my case?

Margie


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to