I have a model defined like below in models.py
class ImageGrab(models.Model):
title = models.CharField(max_length=50)
slug=models.CharField(max_length=200)
age=models.ForeignKey(Age, on_delete=models.CASCADE)
gender=models.ForeignKey(Gender, on_delete=models.CASCADE)
masked=models.ForeignKey(Mask, on_delete=models.CASCADE)
withBackpack=models.ForeignKey(Backpack, on_delete=models.CASCADE)
Filters for which are defined as below in filters.py:
class ImageFilterAge(django_filters.FilterSet):
class Meta:
model = ImageGrab
fields = ['age']
###others similar to this
class ImageFilter(django_filters.FilterSet):
class Meta:
model = ImageGrab
fields = ['age', 'gender', 'masked', 'withBackpack']
The view is like below defined in views.py
def images(request):
imagelist = ImageGrab.objects.all()
imagefilter = ImageFilter(request.GET, queryset=imagelist)
agefilter = ImageFilterAge(request.GET, queryset=imagelist)
genderfilter=ImageFilterGender(request.GET, queryset=imagelist)
maskedfilter= ImageFilterMask(request.GET, queryset=imagelist)
backpackfilter = ImageFilterBackpack(request.GET, queryset=imagelist)
return render(request, 'imglist.html', {'filter': imagefilter,'agefilter': agefilter.form, 'genderfilter':genderfilter.form, 'maskfilter':maskedfilter.form, 'backpackfilter':backpackfilter.form})
My template is like this, in imglist.html
<form method="get" name="search" id="search">
<br>
<br>
<br>
<br>
</form>
This is rendered by default as dropdown select form as given in image link below. I want to change this to say checkbox multiple select and/ or radio button for the filters. Filtering Using Dropdown
How to go about doing this?
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire