Custom attributes of Form Fields

9 views
Skip to first unread message

vpetkov

unread,
Aug 23, 2011, 9:30:03 AM8/23/11
to Django users
Hi,

I have run into a problem that doesn't seem to have a trivial
solution in Django: I would like to have a form field that contains
parts of the html output so that it is not rendered directly by
Widget.render(), but in the template itself.

On a more concrete basis, let there be a forms.Form with a
MultipleChoiceField form field whose widget produces a collection of
checkboxes. I could simply override the CheckboxSelectMultiple's
render() function in order to group them in various ways, but I am
aiming for a more flexible approach. Suppose that I have already
overridden the render() function so that it produces a dictionary
containing the html code for each checkbox separately. What I would
like to have in the template is:

{{ form.tueren.A}}
{{ form.tueren.B }},
etc.

Now, adding attributes/methods to the MultipleChoiceField instance is
easy, but since what the template sees is a BoundField() instance, I
have no way to access my additional attributes. Did anybody encounter
this problem already and how can it be solved in an elegant way?

Best regards,
Venelin Petkov





Reply all
Reply to author
Forward
0 new messages