django:使用管理员日期选择器 [英] django : using admin datepicker

查看:21
本文介绍了django:使用管理员日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我自己的 Django 表单中使用管理员日期选择器.

I'm trying to use the admin datepicker in my own django forms.

大致遵循此处的讨论: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/样式等

然而,当我尝试查看我的表单时,我没有看到好的小部件;只是一个普通的文本框.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 :

gettext 未在 calendar.js 中定义(第 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:卡尔指出这几乎是 以自定义形式使用 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)

推荐答案

不,这不是错误.

它试图调用 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:

http://groups.google.com/group/django-users/browse_thread/thread/2f529966472c479d#

也许是你,无论如何,以防万一.

Maybe it was you, anyway, just in case.

这篇关于django:使用管理员日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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