Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the cleanest, simplest-to-get running datepicker in Django?

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?

like image 815
Michael Morisy Avatar asked Jul 29 '10 21:07

Michael Morisy


People also ask

What is datetime picker?

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.

What is widget in Django?

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 <!


1 Answers

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:

enter image description here

like image 163
avi Avatar answered Oct 05 '22 07:10

avi