widget rendering custom html

63 views
Skip to first unread message

Stefano Tranquillini

unread,
Mar 27, 2018, 4:31:46 AM3/27/18
to Django users
Hi all,

I would like to personlize a widget adding an extra link. In particular I want to change the forms.widgets.CheckboxSelectMultiple .
I've read this: https://docs.djangoproject.com/en/2.0/ref/forms/renderers/  but I can't still make it working, I did this piece of code

class MultiChoiceFilterWidget(forms.widgets.CheckboxSelectMultiple):
 template_name
= 'web_admin/partial/checkbox.html'

class PurposesChoiceForm(ModelForm):
class Meta:
 model = MyModel
 fields = ('myField',)
 widgets = {
 'myField': forms.widgets.CheckboxSelectMultiple,
 }

(indented correctly)

However, there's no way to make it running, what else should I do?

I also tried to put the .html directly inside my app template folder such as web/template/django/forms/widget/checkbox.html but with no luck.

does anyone can point me to a working example or tutorial?

do I've to setup the TemplatesSetting or is there another way to do it?


PS: i would like to personlize the widget just for this form, and not for all the forms.

Stefano Tranquillini

unread,
Apr 6, 2018, 7:11:43 AM4/6/18
to Django users
The problem was that I've used cispy-form and apparently they don't work as expected.

PS: i wrote a post about how I modified the widget and the rest to make it look different, https://stefanotranquillini.wordpress.com/2018/04/03/beautiful-django-widget-for-multi-selection/
Reply all
Reply to author
Forward
0 new messages