Simple library to enable togglefield in Django
How to enable the app:
- Install the library from
Github
pip install git+https://github.com/mattiagiupponi/django-togglefield.git@master
- Enable the app in your Django Project by adding it into the
INSTALLED_APPS
INSTALLED_APPS = [
....,
'togglefield',
....
]
- Define the field into your form:
from django.forms import forms
from togglefield.forms import ToggleSwitchFormField
class FormWithToggle(forms.Form):
your_name = forms.CharField(label='Your name', max_length=100)
toggle = ToggleSwitchFormField(required=False)
- Render your form in your html page:
views.py
def index(request):
context = {
"form": FormWithToggle
}
return render(request, 'app/index.html', context)
index.html
{{form.as_p}}
- Enjoi your field