Django how to compare correctly against django.utils.timezone. localtime and PostgreSQL time with time zone?


I have a legacy PostgreSQL table with time with time zone column.

in I have the filed set to models.TimeField

I want to compare accessed Django.utils.timezone.localtime() with db_field_time_with_time_zone

I have tried below:

# let's say now=20:00 and db_field_time_with_time_zone=16:00
now = timezone.localtime()
data = timezone.datetime.combine(timezone.localdate(), db_field_time_with_time_zone)
self.assertTrue(now > data) # I get False...

In the raw PostgreSQL column it’s stored as 16:00:00+09:00

but when I retrieve data using python shell it returns 16:00:00+00:00 and I also think this is the cause of this problem.

In my

TIME_ZONE = 'Asia/Tokyo'
USE_TZ = True