简体   繁体   English

在Django Admin中覆盖DateTimeShortcut

[英]Override DateTimeShortcut in Django Admin

I'm trying to implement the top solution here, the one that only uses javascript: Django: how to change the choices of AdminTimeWidget 我正在尝试实现此处的最佳解决方案,即仅使用javascript的解决方案: Django:如何更改AdminTimeWidget的选择

It basically uses regex to create the different time choices by overriding the time options. 它基本上是使用正则表达式通过覆盖时间选项来创建不同的时间选择。

The only problem I have is that my script loads before DateTimeShortcuts.js, so I get an Uncaught ReferenceError: DateTimeShortcuts is not defined. 我唯一的问题是我的脚本在DateTimeShortcuts.js之前加载,因此出现了Uncaught ReferenceError:DateTimeShortcuts未定义。 Does anyone know how I can force the DateTimeShortcuts.js file to load after my js file that references it? 有谁知道我该如何强制DateTimeShortcuts.js文件在引用它的js文件之后加载?

If I create a second reference to DateTimeShortcuts.js, it'll work properly, but I'll have two clocks up there, only the 2nd one will modify, because it's loading after the 2nd DateTimeShortcuts.js 如果我创建第二个对DateTimeShortcuts.js的引用,它将正常工作,但是在那里会有两个时钟,只有第二个时钟会被修改,因为它将在第二个DateTimeShortcuts.js之后加载

I'm calling my file like this, where admin_clock.js references DateTimeShortcuts.js and has the override code: 我正在这样调用我的文件,其中admin_clock.js引用DateTimeShortcuts.js并具有覆盖代码:

class EventAdmin(admin.ModelAdmin):
    list_filter = ('film', 'partner',)
    list_display = ('id', partner', 'film', 'date_time', 'venue_name', 'city')
    class Media:
         js = ('tiny_mce/tiny_mce.js', 'tiny_mce/textareas.js', 'admin_clock.js',)

Apologies for not commenting on the original answer, I need more points to comment there. 很抱歉没有评论原始答案,在此我需要多点评论。

我解决此问题的方法是将javascript直接添加到我的change_form模板版本的extrahead块中,覆盖该模板中的该块: https ://docs.djangoproject.com/zh/1.6/ref/contrib/admin/ #压倒一切的管理员模板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM