I have this:
class HouseForm(forms.ModelForm):
amenities = ModelMultipleChoiceField(
queryset=Amenity.objects.all(),
widget=forms.CheckboxSelectMultiple(),
required=False
)
Is there a way I can construct my own list of checkboxes? Instead of the default in unordered list?
Here’s what I hope to achieve:
<select>
{% for a in house_form.amenities %}
<option value="{{ a.value }}" {% if a.checked %}selected="selected"{% endif %}>
{{ a.option_name }}</option>
{% endfor %}
</select>
I hope to be able to customize the list, break into 3 columns, etc. Any suggestions?
I know I can passed in a list of all the amenities and a list of amenities in the house and do a for loop to compare it. I just find it not-elegant and inefficient.
subclass forms.CheckboxSelectMultiple (render() method?) to give you the required output.