I have a datetimefield, which I am inputting data using the following form field:
delivery_pickup = forms.DateTimeField(label = "Delivery or Pickup Appointment",
required = False,
widget=forms.DateTimeInput(attrs={'type':'datetime-local'}))
A nice little datetime widget appears automatically due to the type attribute declaration. The problem is when I try to submit using the widget, I get an error, and when I remove the widget and look at the input as a simple string, it includes a random T in between the date and the time, like so: 2021-09-26T13:17
Removing the T manually causes the error to go away. What's the best way to remove the T? Is it by formatting the string within the input field? Creating a clean method? Some other technique? Any help is appreciated.
EDIT: Evidently, the type declaration of 'datetime-local' is what causes it to be formatted it into an isot datetime string: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
The above article also gives a javascript function for converting the date to an ISO string: Date.toISOString() (2nd edit: actually, this also defaults to isot not iso format...)
The issue is I don't know how it interacts with the Django object. Can I call a JS function from inside of a form field or a widget? probably not, it would need to reside in the HTML for the page. The problem is that for my forms, I have simply looped over the form fields like so:
{% for field in form %}
<tr>
<td class="column_name">{{field.label}}</td>
<td class="column_data">{{field}}</td>
<td class="column_data">{{field.errors}}</td>
</tr>
{% endfor %}
Which means I haven't distinguished the singular one for datetime. So I'm at a bit of a standstill, appreciate any help on this last point