I am using the Django rest framework with Postgresql. From the Django docs, I understood that Postgres will store the DateTime in UTC only and Django converts it back to the local time while displaying in the templates. However, I am not using templates. I am using DRF to create APIs which are consumed by a Vue app. I have two questions -
- Why Django Model DateTime fields are converted to "timestamp with time zone" type column if values are always stored in UTC?
- How to return DateTime values in local time from the Django rest framework.
Here is my settings File -
TIME_ZONE = 'Asia/Calcutta'
USE_TZ = True
REST_FRAMEWORK = {
'DATE_INPUT_FORMATS': ["%d-%m-%Y",],
'DATE_FORMAT': "%d-%m-%Y",
'DATETIME_FORMAT': "%d-%m-%Y %H:%M:%S",
}
Special Note - using django.utils.timezone.localtime(timezone.now()) creates a value in localtime but it is converted back to UTC while storing in DB.
Any help will be highly appreciated. Thanks a lot for your time and help.