django-timezones:如何使用这个应用程序?
我正在尝试使用 django-timezones 但找不到与之相关的任何文档。我读了它的一些代码,但完全迷失了。例如,模型的 LocalizedDateTimeField 具有如下构造函数:
def __init__(self, verbose_name=None, name=None, timezone=None, **kwargs):
时区是一个参数。但是模型字段如何事先知道它应该是哪个本地时区呢?根据我的理解,最佳实践应该是所有时间戳都存储为 UTC 时间,并且仅在向用户显示时将其转换为本地时间。所以这个领域对我来说完全没有任何意义。在我看来,当您定义模型时,您必须将时区传递给该字段。但时区对于建模来说是竞争性的,因为用户可能来自不同的时区。
I'm trying to use django-timezones but can't find any document relating to it. I read some codes of it and got totally lost. For example, LocalizedDateTimeField of the model has a constructor like:
def __init__(self, verbose_name=None, name=None, timezone=None, **kwargs):
timezone is an argument. But how can a model field know beforehand what localised timezone it should be? As per my understanding, the best practice should be that all the timestamps are stored as UTC time and only convert it to local time when showing to users. So this field totally doesn't make any sense to me. It appears to me that you have to pass a timezone to this field when you are defining a model. But timezones are agonistic to model since users can be from different timezones.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
三个地方值得一看...
Three places to look ...
对于其他想要如何使用此模块的人,请检查 timezones/timezones_tests/tests.py 下的测试。他们对如何使用它给出了清晰的想法。
For anyone else looking how to use this module, check the tests under timezones/timezones_tests/tests.py. They give a clear idea on how to use it.