How to customize django form shortcut

class permForm(forms.Form):
    def __init__(self, data=None, **kwargs):
        super(permForm, self).__init__(data, **kwargs)

        for item in list(AdminMenu.objects.filter(parent_id=0)):
            self.fields['menu_%d' % item.id] = forms.BooleanField(label=item.title)
            for childitem in list(AdminMenu.objects.filter(parent_id=item.id)):
                arr=[]
                arr.append(str(item.id))
                arr.append(str(childitem.id))
                self.fields['menu_%s' % '_'.join(arr)] = forms.BooleanField(label=childitem.title)

It will return

category: checkbox

add category: checkbox

List Category: checkbox

Food: checkbox

Add Fooditems: checkbox

Fooditem list: checkbox

Tables: checkbox

Add tables: checkbox

List of tables: checkbox

Users: checkbox

Browse users: checkbox
How can I display it as the following

category: .

add category: checkbox

List Category: checkbox

Food : checkbox

Add Fooditems: checkbox

Fooditem list: checkbox

Tables : checkbox

Add tables: checkbox

List of tables: checkbox

Users : checkbox

Browse Users: checkbox

I WANT TO MAKE A LOCAL CATEGORY OF PARENTS WHICH REFUSES TO CHILD. POSSIBLE? I DO NOT WANT TO USE HEAVY ENCODED FORMS

+5
source share
1 answer

Here is an example of how to add HTML to create labels:

from django.template.defaultfilters import mark_safe


class MyForm(forms.Form):
    my_field = forms.CharField(
        max_length=100,
        label = mark_safe('<strong>My Bold Field Label</strong>')
    )
+13
source

All Articles