Nanor
Nanor

Reputation: 2550

'CheckboxSelectMultiple' object has no attribute 'label'

I'm dynamically creating a form based on the number of skills in the database. It's created like so:

class FilterFreelancerForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(FilterFreelancerForm, self).__init__(*args, **kwargs)
        skills = Skill.objects.all()
        for skill in skills:
            self.fields['custom_%s' % skill] = forms.CheckboxSelectMultiple()

My view simply instantiates the form object like so form = FilterFreelancerForm() and returns it to the template to be rendered with {{form}}. This causes the AttributeError: 'CheckboxSelectMultiple' object has no attribute 'label'.

Why is this?

Upvotes: 0

Views: 292

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599956

CheckboxSelectMultiple is a widget, not a field.

Upvotes: 3

Related Questions