DateField selector widget in UpdateVeiw

When I create an object, I’m setting its DateField. Later a user may want to edit the object’s date and I’m using a class based UpdateView for this. The user is given a textbox for entering in the date (it’s a text input type field as far as I can tell), I’m wondering if I can include a date selector widget with it?

Yes. If you look at the Django admin pages and the html / js loaded on it for a page containing a Date field, you can see one example.

I came across a simple HTML5 solution. In your forms, you create a class that has the input type = ‘date’, which is the hmtl5 date picker. Your widget then uses class.

model Book(models.Model):
	name = models.CharField(max_length=30)
	date_read = models.DateField()
	
class DateInput(forms.DateInput):
    input_type = 'date'

class BookUpdateForm(ModelForm):
    class Meta:
        model = Book
        fields = ('name', 'date_read',)
        widgets = {
            'date_created': DateInput(),
        }