I have a model Property
class Property(models.Model):
PROPERTY_CATEGORIES = (
('flat/apartment 1BHK','flat/apartment 1BHK'),
('flat/apartment 2BHK','flat/apartment 2BHK'),
('flat/apartment 3BHK','flat/apartment 3BHK'),
('house','house'),
('pg/hostel +1 mate','pg/hostel +1 mate'),
('pg/hostel +2 mate','pg/hostel +2 mate'),
('pg/hostel +3 mate','pg/hostel +3 mate'),
('pg/hostel +4 mate','pg/hostel +4 mate'),
)
name = models.CharField(max_length=200)
proptype = models.CharField(max_length=100, choices=PROPERTY_CATEGORIES)
and my filters.py looks like this
import django_filters
from .models import Property
from django.db import models
from django import forms
class PropertyFilter(django_filters.FilterSet):
PROPERTY_CATEGORIES = (
('flat/apartment 1BHK','flat/apartment 1BHK'),
('flat/apartment 2BHK','flat/apartment 2BHK'),
('flat/apartment 3BHK','flat/apartment 3BHK'),
('house','house'),
('pg/hostel +1 mate','pg/hostel +1 mate'),
('pg/hostel +2 mate','pg/hostel +2 mate'),
('pg/hostel +3 mate','pg/hostel +3 mate'),
('pg/hostel +4 mate','pg/hostel +4 mate'),
)
proptype = django_filters.ChoiceFilter(choices=PROPERTY_CATEGORIES)
class Meta:
model = Property
fields = ['proptype']
filter_overrides = {
models.CharField:{
'filter_class' : django_filters.ChoiceFilter,
'extra' : lambda f: {
'widget' : 'forms.CheckboxInput'
}
}
}
and my html file is
{% block content %}
<form method="get">
<!-- {{ filter.form.as_p }} -->
{% for choice in filter.form.proptype %}
{{ choice.choice_label }}
<span class="radio">{{ choice.tag }}</span>
{% endfor %}
<input type="submit" />
</form>
{% for obj in filter.qs %}
{{ obj }} <br />
{% endfor %}
{% endblock %}
I want to display the choices like as radiobuttons or checkboxes
like a list of categories like house, flat etc like with radiobuttons to select them
but I cant find a way to do this please help