I love the Thauber Schedule datepicker, but it's a datetime picker and I can't get it to just do dates. Any recommendations for nice looking datepickers that come with instructions on how to integrate with a Django date form field?
The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. The DateTimePicker control makes it easy to work with dates and times because it handles a lot of the data validation automatically.
A widget is Django's representation of an HTML input element. The widget handles the rendering of the HTML, and the extraction of data from a GET/POST dictionary that corresponds to the widget. The HTML generated by the built-in widgets uses HTML5 syntax, targeting <!
Following is what I do, no external dependencies at all.:
models.py:
from django.db import models class Promise(models): title = models.CharField(max_length=300) description = models.TextField(blank=True) made_on = models.DateField()
forms.py:
from django import forms from django.forms import ModelForm from .models import Promise class DateInput(forms.DateInput): input_type = 'date' class PromiseForm(ModelForm): class Meta: model = Promise fields = ['title', 'description', 'made_on'] widgets = { 'made_on': DateInput(), }
my view:
class PromiseCreateView(CreateView): model = Promise form_class = PromiseForm
And my template:
<form action="" method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="Create" /> </form>
The date picker looks like this:
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