0

I would like to change the way a widget is rendered in Django. I've read this guide https://docs.djangoproject.com/en/2.0/ref/forms/renderers/ but still I can't make it working.

I've create this widget

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

but it's not working in the sense that the default look-and-feel is displayed, there's no sign of my edits.

In TEMPLATES I've the folder myproject.web and the folder structure is myproject/web/templates/web_admin/partial/checkbox.html

What Am I missing?

(I also tried to put a file in django/forms/widgets/checkbox_select.html that is the file the widget is looking for, but still not working)

edit in settings.py

INSTALLED_APPS = [
   ...
    'web',
  ...
]

in forms.py

class MyChoiceForm(ModelForm):
        class Meta:
            model = MyModel
            fields = ('theField',)
            widgets = {
                'theField': MultiChoiceFilterWidget,
            }

edit2 Update the question to reflect the fact that this works for plain django, not with crispy form.

EsseTi
  • 4,079
  • 5
  • 36
  • 63
  • 1
    Are you using the MultiChoiceFilterWidget? As in do you have code somewhere that says something along the lines of `field_name = forms.SomeField(widget=MultiChoiceFilterWidget)`? – kjpc-tech Mar 28 '18 at 15:52
  • Is `web` an app in `INSTALLED_APPS`? If not you might need to set `FORM_RENDERER`. See [this question](https://stackoverflow.com/questions/46835633/django-widget-template-override-does-not-search-in-the-project-template-director/46836189#46836189). – Alasdair Mar 28 '18 at 15:53
  • Yes for both questions, see the edit in the question – EsseTi Mar 28 '18 at 17:30
  • Your example code looks ok. If you show your real code it might show a problem that isn't in your example form. – Alasdair Mar 28 '18 at 17:39
  • it seems that it's a problem with crispy form.. removing the `crispy` it works. I'm filling in an issue to see how to solve it and update this question – EsseTi Mar 29 '18 at 08:00

0 Answers0