Created
April 7, 2021 15:48
-
-
Save mmtechslv/01b3e05829049354ca2d4ec6d416760f to your computer and use it in GitHub Desktop.
Markdium-Introduction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_filters import FilterSet | |
from django_filters.filters import RangeFilter | |
from .models import People | |
from .forms import PeopleFilterFormHelper | |
from .widgets import CustomRangeWidget | |
class AllRangeFilter(RangeFilter): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
values = [p.age for p in People.objects.all()] | |
min_value = min(values) | |
max_value = max(values) | |
self.extra['widget'] = CustomRangeWidget(attrs={'data-range_min':min_value,'data-range_max':max_value}) | |
class PeopleFilter(FilterSet): | |
age = AllRangeFilter() | |
class Meta: | |
model = People | |
fields = ['age'] | |
form = PeopleFilterFormHelper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment