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>
> Raw link: 
> https://stackoverflow.com/questions/27321692/override-a-django-generic-class-based-view-widget
> Hope this helps, 

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.
Thanks very much for your help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e60942df-354c-44a6-b041-e132aa61566a%40www.fastmail.com.

Reply via email to