timezone - Record create and Update time not stored in localtime django -
i have model "member" there 2 fields "created_at" , "updated_at". originally, defined below :
created_at = models.datetimefield(auto_now_add=true, null=true) updated_at = models.datetimefield(auto_now_add=true, null=true)
my settings.py have use_tz = true , time_zone = "america/new_york".
i have custom middleware defined activate timezone selected user.
current_tz = pytz.timezone("<user defined timezone>") timezone.activate(current_tz)
then, update fields store user localtime:
created_at = models.datetimefield(default= lambda: timezone.localtime(timezone.now()), null=true) updated_at = models.datetimefield(default= lambda: timezone.localtime(timezone.now()), null=true)
now, when update member record , check updated_at time, showing same utc timezone instead of localtime of user.
is django stores datetime values in db in utc or missing here
all requirement should focus on use_tz = true
.
if set use_tz = true
, datetimefield stores utc time. if comment use_tz = true
in settings.py, can want.
but in project, should better open use_tz, if open use_tz, store or internal processing print, utc timezone. when shows in templates, quite convenient time format conversion.
Comments
Post a Comment