I would like to get a date AND time picker for my django model form.
model:
class ServiceBooker(models.Model):
regnr = models.CharField(max_length=255)
namn = models.CharField(max_length=255, null=True, blank=True)
telnr = models.CharField(max_length=255)
email = models.EmailField(max_length=255)
service_date = models.DateTimeField()
booked_date = models.DateTimeField(auto_now=True)
kommentar = models.TextField()
service_name = models.ForeignKey(ServiceType, on_delete=models.CASCADE)
noteringar = models.TextField(default='')
forms.py:
class ServiceBookerForm(forms.ModelForm):
service_date = forms.DateTimeField(input_formats=['%d/%m/%Y %H:%M'],
widget=forms.DateTimeInput(
format='%d/%m/%Y %H:%M',
attrs={'class': 'form-control'}))
class Meta:
model = ServiceBooker
fields = '__all__'
exclude = ('noteringar',)
But on the website it doesn't show the datetimepicker. I know how to fix the date picker with:
'service_date': widgets.DateInput(attrs={'type': 'date'})
but I would like to get a date AND time picker.
Can anyone help me? :-)
Thanks!
Marco helped me to find an answer to this question:
Have you tried datetime-local as type? – Marco