Storing timezone aware datetimes with Django 1.6 and PostGreSQL 9.2

Viewed 916
TIME_ZONE = 'Europe/Paris' # UTC+1
USE_TZ = True

I just want to have all my datetimes TZ-aware in database, but I'm not sure what is the right way to do it, even after reading django doc.

1) First, I tried to use timezone.now() everywhere. If It's 12:19 in Paris, it will return: datetime.datetime(2016, 3, 16, 11, 19, 51, 842247, tzinfo=<UTC>))

It seems to be the normal behaviour: Django converts the datetime to UTC, but not sure if it's a good thing. Am I not losing some data in the process? How to know that data is related to the Paris timezone this way?

2) Then, I tried to use localtime(timezone.now()) everywhere. This time, if it's 12:19 in Paris, I get a: datetime.datetime(2016, 3, 16, 12, 19, 37, 372710, tzinfo=<DstTzInfo 'Europe/Paris' CET+1:00:00 STD>)

Here, the datetime is not converted, and the real timezone info (Paris) is stored into the datetime. I thought is was better, but after some searches, no one seems to process this way. Am I missing something?

Plus, with the second solution, I really expected my objects to be stored in PostGreSQL database with +01 suffix. Not at all. Here is the content of my DB timestamps: 2016-03-16 11:19:01.093176+00

I don't understand how to do all this stuff the right way.

1 Answers
Related