I want to assign values form a simple html form(I dont want to use Django model forms or widgets in this case). All of the fields work fine except the datetime one.
Lets say the html form is as simple as this:
<form action="{% url 'main:create' %}" method="post" class="row form">
{% csrf_token %}
<div class="expense-block" id="expense-block-0" data-block="0">
<div class="col-md-2">
<div class="form-group">
<label for="id_name">Name:</label>
<input type="text" name="name" class="form-control" required id="id_name">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="id_created_at">Date:</label>
<input type="datetime-local" name="created_at" class="form-control" required id="id_created_at">
</div>
</div>
</div>
<input type="submit">
</form>
As you can see for the date input i am using type="datetime-local"
because I want to select both date and time.
The model is simple:
class Expenses(models.Model):
name = models.CharField(max_length=200)
created_at = models.DateTimeField()
However when i save model I get error:
The Expenses could not be created because the data didn't validate.
Now the reason I am getting this error is because the 'create_at' value that i get from the post looks like this:
2018-03-09T11:11
So the question is, is it possible with Python to format this date to a normal datetime object? If not, what else can I do in my case?