On Fri, Oct 8, 2021, at 8:41 AM, MR INDIA wrote:
> Answer to this query on stack overflow
> <
https://stackoverflow.com/questions/27321692/override-a-django-generic-class-based-view-widget>
Thanks very much for the link MR INDIA.
That is exactly what Im looking to do, however, its not working for me for some reason.
How can I check if I am getting the desired result in my rendered HTML?
I am working with a DateTimeField. So I should be getting a type='datetime' in the <input> tag correct?
I don't understand why other fields like a CharField with choices, automatically, renders a <select> tag on my form, without even specifying a widget for it as described in the link. Is it not expected that a DateTimeField would render the type:'datetime' in the html form? (without any additional modifications). The link above was created 6 years ago, has this not changed in all that time?
I will show you what I have:
--models.py--
class Lesson(models.Model):
...
time = models.DateTimeField("Fecha y Hora")
--views.py--
class LessonCreateView(CreateView):
model = Lesson
template_name = 'new_lesson.html'
form_class = LessonForm
def form_valid(self, form): # new
form.instance.instructor = self.request.user
return super().form_valid(form)
--forms.py--
class LessonForm(forms.ModelForm):
class Meta:
model = Lesson
fields = ['title', 'time', 'nivel']
widgets = {
'time': forms.DateTimeInput()
}
In my rendered HTML I however get a type="text" for the 'time' field.