#31471: DateTimeField is returned as str instead of as datetime object, when
using
reverse lookup
-------------------------------------+-------------------------------------
Reporter: Fonville | Owner: nobody
Type: Bug | Status: new
Component: | Version: 3.0
Uncategorized |
Severity: Normal | Keywords: datetime, OneToOne
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I have a Telemetry class/model with a DateTimeField:
{{{
class Telemetry(models.Model):
time_stamp = models.DateTimeField()
}}}
Whitin this class/model the time_stamp field is correctly treated as a
Python `datetime` object
Telemetry has a OnetoOne relationship with another model:
{{{
class ExtraTelemetry(models.Model):
telemetry = models.OneToOneField(Telemetry, on_delete=models.CASCADE,
primary_key=True)
}}}
in this related ExtraTelemetery object I am fetching the value of the
DateTimeField with:
`self.telemetry.time_stamp`
You'd expect this to be a Python `datetime` object too, but instead it
returns a `str` object (e.g. `"2020-04-15T17:03:05Z"`)
I am only able to use the field as datetime object by parsing it myself
with `dateutil.parser.parse(self.telemetry.time_stamp)`
I think this is a bug, because it should be a datetime object and not a
string, even when fetched through a relationship.
Django version is 3.0.5 with Python3.8.2 and SQLite
--
Ticket URL: <https://code.djangoproject.com/ticket/31471>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.3e08043113b6b8045a765dfe9fccc6ab%40djangoproject.com.