This file contains 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.shortcuts import render | |
from .filters import PeopleFilter | |
def index(request): | |
people_filter = RangeFilter(request.GET) | |
return render(request, 'index.html', {'people_filter':people_filter}) |
This file contains 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 crispy_forms.helper import FormHelper | |
from crispy_forms.bootstrap import StrictButton | |
from crispy_forms.layout import Field, Layout | |
from django import forms | |
from django_filters.fields import RangeField | |
class PeopleFilterFormHelper(forms.Form): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.helper = FormHelper(self) |
This file contains 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 myapp.views import index | |
urlpatterns = [ | |
... | |
path('', index), | |
] |
This file contains 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.forms.widgets import HiddenInput | |
from django_filters.widgets import RangeWidget | |
class CustomRangeWidget(RangeWidget): | |
template_name = 'forms/widgets/range-slider.html' | |
def __init__(self, attrs=None): | |
widgets = (HiddenInput(), HiddenInput()) | |
super(RangeWidget, self).__init__(widgets, attrs) |
This file contains 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
$ python manage.py startapp myapp |
This file contains 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
$ mkdir myproject | |
$ cd myproject | |
$ pipenv shell |
This file contains 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
<div class="form-group numeric-slider" {% include "django/forms/widgets/attrs.html" %}> | |
<div class="numeric-slider-range ui-slider ui-slider-horizontal ui-slider-range"></div> | |
<span class="numeric-slider-range_text" id='{{ widget.attrs.id }}_text'> | |
{{ widget.value_text }} | |
</span> | |
{% for widget in widget.subwidgets %} | |
{% include widget.template_name %} | |
{% endfor %} | |
</div> |
This file contains 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
$ python manage.py makemigrations | |
$ python manage.py migrate |
This file contains 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
import django_filters | |
from .models import People | |
class PeopleFilter(django_filters.FilterSet): | |
age = django_filters.AllValuesFilter() | |
class Meta: | |
model = People | |
fields = ['age'] |
This file contains 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
{% load static %} | |
{% load crispy_forms_tags %} | |
<head> | |
<link rel="stylesheet" href="{% static 'custom_slider.css' %}"> # CSS of our range-slider. | |
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | |
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> | |
</head> |