如何使Django-admin时区知道? [英] How do you make Django-admin timezone aware?

查看:148
本文介绍了如何使Django-admin时区知道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将datetime信息作为UTC存储在数据库中。我正在使用Django管理员显示此信息。

I have datetime information stored in the database as UTC. I'm displaying this info using Django admin.

有没有办法在Django管理员中显示最终用户当前时区的日期时间信息?

Is there a way to display datetime information to the end-user's current timezone in Django admin?

通常我认为这样的逻辑是在模板/视图层,但是,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).

一个想法是在模型中对DateTimeField进行子类化,并使其在将数据从数据库中获取时转换为本地时区,尽管我不确定这将会有效。

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.

推荐答案

本地化的时区支持可在即将发布的 Django 1.4

Localized timezone support is available in the soon-to-be-released Django 1.4.

这篇关于如何使Django-admin时区知道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆