1

I have an app that uses

import datetime

datetime.datetime.now()
default=datetime.now
auto_now=True
auto_now_add=True

I'm changing the above codes to the below.

from django.utils import timezone

timezone.now() # instead of datetime.datetime.now()
default=timezone.now # instead of datetime.now
auto_now # override save() or pre_save() .. ok don't need this change in recent django.
auto_now_add # override post_save() to set time when `created`.. don't need this change either

Am I missing something or doing something superflous?

I'm using an open source app and it uses a lot of datetime.datetime ..
It's really pain to change all that.. hope there was an easier way.

eugene
  • 39,839
  • 68
  • 255
  • 489
  • I checked django 1.4.5 source code, and auto_now and auto_now_add uses timezone.now() instead of datetime.now() – eugene Jul 16 '13 at 03:56

1 Answers1

1

In your settings file you have to set USE_TZ = True. From docs:

Time zone support is disabled by default. To enable it, set USE_TZ = True in your settings file

Aamir Rind
  • 38,793
  • 23
  • 126
  • 164