django:使用admin datepicker [英] django : using admin datepicker
问题描述
我试图以自己的django表单使用admin datepicker。
I'm trying to use the admin datepicker in my own django forms.
大致遵循这里的讨论: http://www.mail-archive.com/django-users@googlegroups.com/msg72138.html
Roughly following the discussion here : http://www.mail-archive.com/django-users@googlegroups.com/msg72138.html
我有
a)在我的forms.py中包含行
a) In my forms.py included the line
from django.contrib.admin import widgets
b)并使用这样的小部件:
b) and used the widget like this :
date = forms.DateTimeField(widget=widgets.AdminDateWidget())
c)在我的实际模板中,我添加了:
c) And in my actual template I've added :
{{form.media}}
要包含js / style等。
To include the js / styles etc.
但是,当我尝试查看我的表单时,我没有很好的小部件;只是一个普通的文本框。 Firefox JavaScript错误控制台显示:
However, when I try to view my form I get no nice widget; just an ordinary text box. And the Firefox javascript error console shows me :
在calendar.js中没有定义gettext(第26行)
gettext is not defined in calendar.js (line 26)
和
addEvent在DateTimeShortcuts.js(第254行)中未定义
addEvent is not defined in DateTimeShortcuts.js (line 254)
任何建议?这是Django自己的JavaScript库中的错误?
Any suggestions? Is this a bug in Django's own javascript library?
更新:基本上,需要包含核心和(或假)i18lization
Update : Basically, need to include the core and (or fake) the i18lization
更新2:Carl指出这与以自定义形式使用Django时间/日期小部件(尽管从不同的位置开始)
Update 2 : Carl points out this is pretty much a duplicate of Using Django time/date widgets in custom form (although starting from a different position)
推荐答案
不,这不是一个bug。
No, it's not a bug.
它试图在js中调用gettext()国际化功能。你可以像python代码或模板一样做js国际化,这只是一个不太了解的功能。
It's trying to call the gettext() internationalization function in js. You can do js internationalization much like you do it in python code or templates, it's only a less known feature.
如果你不在项目中使用js国际化
If you don't use js internationalization in your project you can just put.
<script>function gettext(txt){ return txt }</script>
在您的顶层模板中,所以js解释器不会窒息。
in your top template so the js interpreter doesn't choke.
这是一个奇怪的方式来解决我知道的。
This is a hacky way to solve it I know.
编辑:
或者您可以包括确切的jsi18n js django管理员参考,以使其工作甚至与其他语言。我不知道是哪一个。
Or you can include the exact jsi18n js django admin references to get it working even with other languages. I don't know which one it is.
今天在django-users上发布了:
This was posted on django-users today:
< a href =http://groups.google.com/group/django-users/browse_thread/thread/2f529966472c479d# =nofollow noreferrer> http://groups.google.com/group/django-users/ browse_thread / thread / 2f529966472c479d#
无论如何,也许是你,以防万一。
Maybe it was you, anyway, just in case.
这篇关于django:使用admin datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!