# My way or an easier way (templates)

**URL:** <https://forum.djangoproject.com/t/my-way-or-an-easier-way-templates/43218>\
**Category:** Templates & Frontend\
**Created:** [October 19, 2025, 4:20pm UTC](https://forum.djangoproject.com/t/my-way-or-an-easier-way-templates/43218 "2025-10-19T16:20:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![FireDragon42](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/firedragon42/32/6690_2.png) [@FireDragon42](https://forum.djangoproject.com/u/FireDragon42)\
**Post date:** [October 19, 2025, 4:20pm UTC](https://forum.djangoproject.com/t/my-way-or-an-easier-way-templates/43218/1 "2025-10-19T16:20:33Z")

</div>

After

> [@How to change a form name in class based view?](https://forum.djangoproject.com/t/how-to-change-a-form-name-in-class-based-view/42896/11):
>
> The templating system is very much designed around being flexible and used in a “generic” manner. Look at the system provided templates for things like the admin and the standard widgets to get some ideas as to just how flexible they can be.

I got curious if there are easier solutions to my coding mess. So 3 problems and my solutions (the mess) and I hope there are easier ways. (The first is a real problem with the checkboxes so that will probably result in a resolved)

**1. Add a searchfield above a list of checkboxes**  
I had a few problems with the default code: ((form}}

- I never see checkboxes
- the search field is never shown at a convenient location in the html and associated with the correct list (can only add this is a manual template)
- I lost my code that showed all checked list items on top of the list (css only) I will add it if I find it again)

the list of phonenumbers resulting from:

```auto
telephoneNumbers = models.ManyToManyField( to=PhoneNumber
                                    ,related_name="person"
                                   )

```

shows it as html not as checkboxes .

I hoped the widget CheckboxSelectMultiple would solve that

```auto
class Meta:
        model = Entity
        fields = " __all__"

        widgets = {
            'telephoneNumbers': forms.CheckboxSelectMultiple(attrs=
            {
                'type': "checkbox",
            }),
      }

```

But that does not change the elements into a checkbox even though the widget name implies it.

Adding the following code works

```auto
class Personform(ModelForm):
    telephoneNumbers = forms.ModelMultipleChoiceField(
            queryset = PhoneNumber.objects.all(),
            widget = forms.CheckboxSelectMultiple(attrs=
                {
                }
            ),
        )

```

but that means I have 'redefined' the field in the form (dont know the right word describing the problem)

So how can I create a checkbox list and how can I place the searchfield in a usefull place? Is that even possible without creating a total manual template for that?

**2: All manual templates**

I had to create templates for some fields and (until yesterday) that resulted in me creating a template for each field. For instance the following code for the fuull name of a person consisting of 3 form fields

```auto
<form method="post" class="edit">
   {% csrf_token %}

   {% include "MyNetwork/form/person/full_name_fields_form.html" %}
   {% include "MyNetwork/form/person/gender_field_form.html" %}
   {% include "MyNetwork/form/person/date_of_birth_field_form.html" %}

 </form>

```

with:

```auto
{% load i18n %}

<div class="form-element-group">
  <label for="{{ form.familyName.id_for_label }}">{% translate "full name"%}</label>
  <span>
  {{ form.firstName }}
  {{ form.nameAffix }}
  {{ form.familyName }}
  </span>

  {% if form.firstName.help_text or form.nameAffix.help_text or form.familyName.help_text %}
  <div class="help">
     {{ form.firstName.help_text }} 
     {{ form.nameAffix.help_text }}
     {{ form.familyName.help_text }}
  </div>
  {% endif %}

  {% if form.firstName.errors or form.nameAffix.errors or form.familyName.errors %}
  <div class="errors">
    {{ form.firstName.errors }}
    {{ form.nameAffix.errors }}
    {{ form.familyName.errors }}    
  </div>
  {% endif %}

</div>

```

Because I included one field this way it seams I need to add all fields this way. And because the default template code does not perform like expected (for me) that means a lot of templates to add with `include`.  
And worse… a lot to correct if I make the same mistake in every template ☹ And I did that to many times. I expected `{{ person_form.firstName }}` to create all associated fields like label, formfield errors and help\_text but it only adds the form field.`

A bit clearer. I expected the result from a template like this:

```auto
{% load i18n %}

<div class="formFieldWrapper">
  <label for="{{ form.firstName.id_for_label }}">{{ form.firstName.label }}</label>

  {{ form.firstName }}

  {% if form.firstName.help_text %}
    <div class="help">
    {{ form.firstName.help_text }} 
    </div>
  {% endif %}

  {% if form.firstName.errors %}
    <div class="errors">
      {{ form.firstName.errors }}
    </div>
  {% endif %}
</div>

```

But I only get the form field:

```auto
<input type="text" name="firstName" placeholder="First name" size="30" maxlength="60" class="textinput form-control" id="id_firstName">

```

Crispy came to the rescue though (I found out yesterday) with  
`{{person_form.firstName|as_crispy_field}}`

But is there a way without crispy to do this the easy way?.. add all with one commment. online people suggest `{{person_form.firstName}}` should do that but sadly it doesnt. Can it be easyer then the crispy solution?

**3. place multiple fields in a row**  
I want to place the name fields in a row like  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/2/2/222592fcc41437cfcc5f377de0e362b28c4bc680.png)

With

```auto
{% load i18n %}

<div class="form-element-group">
  <label for="{{ form.familyName.id_for_label }}">{% translate "full name"%}</label>
  <span>
  {{ form.firstName }}
  {{ form.nameAffix }}
  {{ form.familyName }}
  </span>

  {% if form.firstName.help_text or form.nameAffix.help_text or form.familyName.help_text %}
  <div class="help">
     {{ form.firstName.help_text }} 
     {{ form.nameAffix.help_text }}
     {{ form.familyName.help_text }}
  </div>
  {% endif %}

  {% if form.firstName.errors or form.nameAffix.errors or form.familyName.errors %}
  <div class="errors">
    {{ form.firstName.errors }}
    {{ form.nameAffix.errors }}
    {{ form.familyName.errors }}    
  </div>
  {% endif %}
</div>

```

it works and with crispy I might have a bit different but same solution:

```auto
<div class="row">
    {{ person_form.firstName|as_crispy_field}}
    {{ person_form.nameAffix|as_crispy_field}}
    {{ person_form.familyName|as_crispy_field}}
</div>

```

the solution with FormHelper did nothing. I probably did something wrong:

```auto
    def __init__ (self, *args, **kwargs):
        super(). __init__ (*args, **kwargs)

        self.helper = FormHelper()
        self.helper.layout = Layout(
            Row(
                Column('firstName', css_class='test'),
                Column('nameAffix', css_class='test'),
                Column('familyName', css_class='test'),
                css_class='test2'
            ),
            'dateOfBirth',
            'gender',

        )

```

What is the best solution here?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 19, 2025, 7:27pm UTC](https://forum.djangoproject.com/t/my-way-or-an-easier-way-templates/43218/2 "2025-10-19T19:27:20Z")

</div>

> [@FireDragon42](#):
>
> the list of phonenumbers resulting from:
> 
> ```auto
> telephoneNumbers = models.ManyToManyField( to=PhoneNumber
> ,related_name="person"
> )
> 
> ```
> 
> shows it as html not as checkboxes .

Where is this definition? (Which model is it defined in?)

---

<div class="post-metadata">

**Author:** ![FireDragon42](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/firedragon42/32/6690_2.png) [@FireDragon42](https://forum.djangoproject.com/u/FireDragon42)\
**Post date:** [October 19, 2025, 8:01pm UTC](https://forum.djangoproject.com/t/my-way-or-an-easier-way-templates/43218/3 "2025-10-19T20:01:48Z")

</div>

```auto
class Entity(models.Model):
    addresses = models.ManyToManyField( to=Address
                                       , related_name="address_entities_set"
                                       , blank=True )

    websites = models.ManyToManyField(to=Website
                                      , related_name="website_entity_set"
                                      , blank=True)

    telephoneNumbers = models.ManyToManyField( to=PhoneNumber
                                    ,related_name="phonenumber_entity_set"
                                   )
    emails = models.ManyToManyField(to=Email
                                    , related_name="emails_entity_set"
                                    , blank=True)

```

and

```auto
class Person(Entity):
    pass

```

Next I use a form to show it but it shows the list like:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/e/e/eeed5a4003d50dbb09beb558b94bf7e082e3e608.png)

No checkboxes

```auto
class Meta:
     'telephoneNumbers': forms.CheckboxSelectMultiple(attrs=
            {
                'type': "checkbox",
            }),

```

The person\_form uses

```auto
{{ person_form | crispy}} to show the fields

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 19, 2025, 8:47pm UTC](https://forum.djangoproject.com/t/my-way-or-an-easier-way-templates/43218/4 "2025-10-19T20:47:42Z")

</div>

Using a trivial analogue (User and Group models), this works when rendering a form directly.

For example the following works in the Django shell:

```auto
from django import forms
from django.template import Template, Context

class TestForm(forms.ModelForm):
     class Meta:
         model=User
         fields=['username', 'groups']
         widgets={'groups': forms.CheckboxSelectMultiple(attrs={})}

form = TestForm()

template = Template('{{form}}')
context = Context({'form': form})

print(template.render(context))

```

yields:

```auto
<div>
    <label for="id_username">Username:</label>

<div class="helptext" id="id_username_helptext">Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.</div>

<input type="text" name="username" maxlength="150" required aria-describedby="id_username_helptext" id="id_username">
    
</div>

  <div>
    <fieldset aria-describedby="id_groups_helptext">
  <legend>Groups:</legend>

<div class="helptext" id="id_groups_helptext">The groups this user belongs to. A user will get all permissions granted to each of their groups.</div>

<div id="id_groups"><div>
    <label for="id_groups_0"><input type="checkbox" name="groups" value="1" id="id_groups_0">
 Group 1</label>

</div><div>
    <label for="id_groups_1"><input type="checkbox" name="groups" value="2" id="id_groups_1">
 Group 2</label>

</div><div>
    <label for="id_groups_2"><input type="checkbox" name="groups" value="3" id="id_groups_2">
 Group 3</label>

</div><div>
    <label for="id_groups_3"><input type="checkbox" name="groups" value="4" id="id_groups_3">
 Group 4</label>

</div>
</div></fieldset>
</div>

```

So, this implies to me that there’s something else involved here. Could be an overridden template, could be some other third-party library involved, could be any number of things.

The Django Debug Toolbar can be helpful with situations like this, especially if you set the `SKIP_TEMPLATE_PREFIXES` to display all the templates being rendered. (It will generate a _lot_ of output, but sometimes that’s necessary.)

---

<div class="post-metadata">

**Author:** ![FireDragon42](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/firedragon42/32/6690_2.png) [@FireDragon42](https://forum.djangoproject.com/u/FireDragon42)\
**Post date:** [October 20, 2025, 1:10pm UTC](https://forum.djangoproject.com/t/my-way-or-an-easier-way-templates/43218/5 "2025-10-20T13:10:44Z")

</div>

Thank you. I will use that to see if I can find the solution

---

<div class="post-metadata">

**Author:** ![FireDragon42](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/firedragon42/32/6690_2.png) [@FireDragon42](https://forum.djangoproject.com/u/FireDragon42)\
**Post date:** [November 8, 2025, 12:16pm UTC](https://forum.djangoproject.com/t/my-way-or-an-easier-way-templates/43218/6 "2025-11-08T12:16:57Z")

</div>

> [@KenWhitesell](#):
>
> It will generate a _lot_ of output, but sometimes that’s necessary

That was not an understatement. I did struggle a lot with the ammount of data untill I started using the text find option in the browser. I did **NOT** find any reference to `CheckboxSelectMultiple` or even `Checkbox`. That got me confused.

I have

```auto
class EntityModelForm(ContextModelForm):
    class Meta:
        model = Entity
        fields = " __all__"

        widgets = {
            'addresses': forms.CheckboxSelectMultiple(),

            'websites': forms.CheckboxSelectMultiple(),

            'telephoneNumbers': forms.CheckboxSelectMultiple(),

            'emails': forms.CheckboxSelectMultiple(),
        }

```

And I used

```auto
class PersonModelForm(EntityModelForm):
    prefix="person"

    class Meta:
        model = Person
        fields = " __all__"

```

without the previous widgets in the view to create a new person

I asumed the widgets from the `EntityModelForm` where inherrited in `PersonModelForm`. But they are not. When I finally added:

```auto
        widgets = {
            'addresses': forms.CheckboxSelectMultiple(),

            'websites': forms.CheckboxSelectMultiple(),

            'telephoneNumbers': forms.CheckboxSelectMultiple(),

            'emails': forms.CheckboxSelectMultiple(),
        }

```

to the `PersonModelForm` it all worked.

So when extending a form like I did… where `class PersonModelForm(EntityModelForm)` extends `class EntityModelForm(ContextModelForm)` My conclusions are

- class data like `Meta` data is not inherrited
- data in the `def __init__ (self, *args, **kwargs):` seems to pass over.

What is the best way to deal with this?

---

<div class="post-metadata">

**Author:** ![antoinehumbert](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/antoinehumbert/32/14851_2.png) [@antoinehumbert](https://forum.djangoproject.com/u/antoinehumbert)\
**Post date:** [November 8, 2025, 6:17pm UTC](https://forum.djangoproject.com/t/my-way-or-an-easier-way-templates/43218/7 "2025-11-08T18:17:22Z")

</div>

Make `PersonModelForm.Meta` inherit from `EntityModelForm.Meta`.

That’s explained at [Creating forms from models | Django documentation | Django](https://docs.djangoproject.com/en/5.2/topics/forms/modelforms/#form-inheritance)
