I populate the fields for editing an event. The fields are shown as "DD/MM/YY HH:MM:SS", but when I change any of the values - although preserving the format - and try to save it, it shows the error:
Enter a valid date/time
class EventForm(forms.ModelForm):
...
date = forms.DateTimeField(widget=forms.widgets.DateTimeInput(format="%d/%m/%Y %H:%M:%S", attrs={'placeholder':"DD/MM/YY HH:MM:SS"}))
...
class Meta:
model = Event
views.py
def event(request, category_slug, event_slug):
...
event = Event.objects.get(slug=event_slug)
form = EventForm(instance=my_event)
context_dict["edit_event_form"] = form
...
return render(request, 'handsup/event.html', context=context_dict)
This is how the field is called in event.html:
<div class="form-group">
{{ edit_event_form.date.errors }}
{{ edit_event_form.date.label_tag }}
{{ edit_event_form.date|addclass:"form-control form-style"}}
</div>
Any comment or suggestion is greatly appreciated. Thank you.