I'm having a very annoying problem in Django to work with date. I am sending from my angle a date that I select in a input data
. In my view
, I convert the date to this format: 2017-10-13
When I try to update in my DateField field, I get the error:
TypeError: expected string or bytes-like object
Field in Model:
data_resgate = models.DateField('Data Resgate', null=True, blank=True)
How do I do the update:
model.data_resgate = str(datetime.datetime.strptime(data.get('data_resgate', None), "%Y-%m-%dT%H:%M:%S.000Z").date())
I'm with USE_L10N = True
.
@UPDATE
The worst thing is, when I give python manage.py shell
to do the update manually, when I add the string 2017-10-13
, it saves correctly without error.
@ UPDATE2
When I just get the date received from input date
, and I try to generate a date with datetime
, it does not even convert because I get the date of the input in another way.
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_strptime.py", line 365, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: T00:00:00.000Z