I am having difficulty getting queryset results in my own timezone. for example: model field definition:
some_datetime_field= models.DateTimeField(null=True)
Query:
MyModel.values_list("some_datetime_field",flat=True).first()
returns
datetime.datetime(2019, 11, 5, 14, 56, 16, tzinfo=<UTC>)
instead of returning
datetime.datetime(2019, 11, 5, 6, 56, 16, tzinfo=<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>)
I am working with python V3.7.5, Django V2.2.7 and PostgreSQL V12 as my database. In my setting I have:
TIME_ZONE = "America/Los_Angeles"
USE_TZ = True
USE_I18N = True
USE_L10N = True
From the documentation it says with regard to the "TIME_ZONE" settings: (https://docs.djangoproject.com/en/2.2/ref/settings/#time-zone)
When USE_TZ is True and the database supports time zones (e.g. PostgreSQL), it is an error to set this option.
so I tried to remove the TIME_ZONE from my setting:
USE_TZ = True
USE_I18N = True
USE_L10N = True
but that didnt work either, even worse, when I try to localize it with timezone.localtime(datetime_example)
i get the time in Chicago time:
datetime.datetime(2019, 11, 5, 8, 56, 16, tzinfo=<DstTzInfo 'America/Chicago' CST-1 day, 18:00:00 STD>)
How can I get my query set to return DateTime in my chosen timezone instead of UTC?