Created
August 20, 2018 19:22
-
-
Save bebosudo/eef51f64732e4b0ce2f125ebb6528a2c to your computer and use it in GitHub Desktop.
A HTML5 date django widget to apply to date form fields.
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 import forms | |
# https://github.com/django/django/blob/master/django/forms/widgets.py | |
class HTML5DateWidget(forms.widgets.Input): | |
input_type = 'date' | |
template_name = 'django/forms/widgets/date.html' | |
# Example: | |
class Blog(forms.ModelForm): | |
class Meta: | |
model = models.Blog | |
fields = "__all__" | |
widgets = {'submit_date': HTML5DateWidget()} | |
# It renders: | |
# <input name="submit_date" required="" id="id_submit_date" type="date"> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment