basic problem: i need to create real customized templates for my django forms. That’s it. I’m used to style the forms based on django’s output. This time is different, the html/css template is already done (months before i was hired) and i cannot modify it, so i need django to output exactly that html code.
I’ve read a lot throu django docs, and i found a lot, but i have to admit, i couldn’t put bits and pieces togheter, with order, to do what i need to do.
Now, with CheckboxSelectMultiple the html output is this:
<ul>
<li><input type='checkbox' ...></li>
...
</ul>
What i actually need to do is create something like CustomCheckboxSelectMultiple to output exactly this template:
<ul class="list">
<li class="list-item"><input class="checkbox" type="checkbox" id="..." /><label class="label" for="">...</label></li>
...
</ul>
And so on for other types of form widgets. It’s the only way i can think of to create my forms with that particular layout they gave me.
I’m actually stuck on this, i cannot seem to be able to put everything togheter to start coding my forms.
How can i manage this? If you have any example too, it will be great! Otherwise, just point me towards the right direction please… sadly, looking in the docs, as i said before, didn’t actually help me
Thanks all in advance!
you should subclass the CheckboxSelectMultiple class and override the render method as in:
See original CheckboxSelectMultiple source for inspiration of how to make your new method.
After that your signal the overriding in your Form
And now all your MyCustomForm will use your specific widget for all CheckboxSelectMultiple in it.