I have datetime information stored in the database as UTC. I'm displaying this info using Django admin.
Is there a way to display datetime information to the end-user's current timezone in Django admin?
Usually I think the logic for this would be in the template/view layer, however, Django-admin hides this all away from you and it seems like I would have to override many of the hidden files (which I don't want to do).
One idea is to subclass DateTimeField in the models and make it so that it converts it to local timezone whenever you grab it from the database, though I'm not sure if this will work.
Anyone have any suggestions? Thanks.
You can also use the pytz module to create timezone-aware objects. For this, we will store the current date and time in a new variable using the datetime. now() function of datetime module and then we will add the timezone using timezone function of pytz module.
Django's timezone is set to UTC by default.
utils. tzinfo , is a support system within Django that stores data and time information in UTC in the database. It uses the time-zone-aware- datetime objects internally and translates them to the user's time zone in templates.
First, open the views.py file of your Django application and import the datetime module. Next, use the datetime. now() method to get the current date and time value.
Django 1.4 will introduce timezone support but the admin will still not be using it yet. There are still questions around which timezone implementation to "bless" (pytz), where to store the timezone per user (without built-in schema migration auth.User basically can't get touched without forcing every Django user to sync their database), and there isn't a UI for timezone selection yet.
So the parts are there but it's still DIY at this stage, sorry.
See the thread I started on django-developers http://groups.google.com/group/django-developers/browse_thread/thread/1386a2bf73babc6a
Localized timezone support is available in the soon-to-be-released Django 1.4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With