Django timezones and Postgresql

77 views Asked by At

I know this question has discussed not for the first time but I stuck with a problem and confused a little.

So I have a celery task that should send reminders in time.

In my config:

USE_TZ = True
TIMEZONE = 'Asia/Singapore'

for example I have a model like:

class Reminder(models.Model):
    created =  models.DateTimeField(default=timezone.now)

This is a simplified model it has more fields but problem laying inside DateTime fields.

So then I open django shell and get time like:

timezone.now()
reminder.created

It shows right time in UTC like:

datetime.datetime(2016, 12, 22, 8, 47, 43, 370101, tzinfo=<UTC>) #tz now
datetime.datetime(2016, 12, 22, 8, 47, 43, 370101, tzinfo=<UTC>) #reminder created

But if I run the task from console and set up prints or trying debug with ipdb I got for time above:

2016-12-22 09:17:19.141242+00:00 # tz now
2016-12-22 16:52:43.366542+00:00 # reminder time CONVERT UTC+8 like Singapore but it became UTC now!!!

So, I can't understand how it's going. And of course I can't compare datetimes correctly in this case.

Django 1.8 and DB PostgreSQL

0

There are 0 answers