Save() method in Django model receiving string instead of date object
Currently we're migrating Django from version 1.11.29 to version 3.2.15 and one thing that we noticed is that the DateFields
in the save()
method in models is now a string instead of a Date
object as it used to be.
this is one of the fields that now is a string
service_date_starts = models.DateField(blank=True, null=True,)
is this expected? or is there a way the DateFields
in save()
still be an object without parsing?
This could help you.
Django DateTimeField showing up as string
I let you some information from that question.
Databases don't store Python data types, so the django ORM does some transforming and casting for you to return you an equivalent Python type.
In other words, if you are creating a new record, the value will be a string because there is no existing value to the field.
If the object is being updated, then the value will be an date time object if you haven't updated that field.