'django-filter list of links
I'm using django-filter's ChoiceFilter to generate a dropdown to filter results and it works great.
However a dropdown is not what I have in mind for the design, instead I would like to use a list of links, but I can't find if there is such a filter.
How can I have a list of links instead of a dropdown ?
Current:
Desired:
filters.py
class manufacturerFilter(django_filters.FilterSet):
manufacturer=django_filters.ChoiceFilter(choices=[])
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.filters['manufacturer'].extra['choices'] = [
(wheel, wheel)
for wheel in WheelItem.objects.values_list('manufacturer', flat=True).distinct()
]
Solution 1:[1]
To anyone coming across this I managed to achieve the desired effect using LinkWidget
. This will render each option as a link, instead of a dropdown.
https://django-filter.readthedocs.io/en/stable/ref/widgets.html#linkwidget
manufacturer=django_filters.ChoiceFilter(choices=[],widget = django_filters.widgets.LinkWidget)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Honky Donkey |