I'm looking for a Django Model Field to render a HTML5 range slider like:
<input type="range" min="1" max="100" value="50">
This question comes close to Which Django Form Field can provide me a HTML output of <input type="range" />? but it asks for a form where I would search for an admin field for Django Admin.
Further this discussion shows as well how to use an IntegerField as range slider in forms: https://code.djangoproject.com/ticket/20674
Long story short, can I use forms in Django Admin, or is there already a specific range field?
You can implement a widget, just like Django implements widgets. For example the NumberInput widget [GitHub] looks like:
class NumberInput(Input): input_type = 'number' template_name = 'django/forms/widgets/number.html'
We can do this ourselves, for example with a:
# app_name/widgets.py
from django.forms.widgets import NumberInput
class RangeInput(NumberInput):
input_type = 'range'
then you can use this widget with:
# app_name/forms.py
from app_name.widgets import RangeInput
class MyForm(forms.Form):
myint = forms.IntegerField(widget=RangeInput)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With