Tuesday, March 31, 2015

Hidden fields in formsets

Hi,

I'm using multiple formsets in Create / Update views, and I want to set some hidden fields in it : user_create, date_create on creation, user_update, date_update on update.

I've created a MultiFormsetMixin, which provide machinery to initialize those formsets in my CreateView / UpdateView.
Basicaly, the mixin fill a formset_list containing dicts with {'formset': <formset>, 'name': <prefix for formset>, 'verbose_name': <displayable name>}... The rendering of the formsets uses the same rendering than 'normal' formsets, via a {%for formset in formset_list %}{# formset rendering #}[% endfor %}. The formsets display normaly.

Data initialization is performed through the 'initial' dict. Every forms in the formsets have the same values for those fields, at initialization, so I update each form of the formsets with those values.

My problem is that those hidden fields are not rendered in the template, even in a 'hidden_field'. I've tryed to set 'exclude' and 'hidden_fields' Meta option in my ModelForm object, but it doesn't work.

When I go through the 'form.hidden_fields' I have my formset administrative normal data (id, parent) but not my fields.

Is it possible to render those fields in the template ?

Thanks !

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/13de9082-3dd5-4b3c-bb72-7393e3f0884c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment