Skip to content

Instantly share code, notes, and snippets.

@bebosudo
Created August 20, 2018 19:22
Show Gist options
  • Save bebosudo/eef51f64732e4b0ce2f125ebb6528a2c to your computer and use it in GitHub Desktop.
Save bebosudo/eef51f64732e4b0ce2f125ebb6528a2c to your computer and use it in GitHub Desktop.
A HTML5 date django widget to apply to date form fields.
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