Changing input type in a class based create view

Hi folks

I’ve created a widget to change date input type to a datepicker:

from django import forms

class DateInput(forms.DateInput):
input_type = 'date'

I can use this fine with models I define in forms.py but I was wondering if there’s a way to override the input type in a class based view in views.py. Specifically, CreateView:

class ActionCreate(LoginRequiredMixin, CreateView):
    model = Action
    fields = '__all__'

Any help, much appreciated.
Thanks

The widget used in a form is an attribute of the form, not of the view that is presenting that form.

So what you’re looking for is the form_class attribute of your view that will use your custom form.

1 Like

Yes as Ken says. Defining model and fields on a FormView are shortcuts meaning “create a Form class for me like this.” For any level of customization you need to create the form class yourself.

1 Like

Great, thanks guys. I’ll give that a crack.

Did you find a solution to this? Override Date Input in Create View?