Python 在django admin中自定义change_list.html

Python 在django admin中自定义change_list.html,python,django,django-admin,Python,Django,Django Admin,change\u list.html具有Action部分,其中用户选择一个操作并将其应用于所选项目(queryset) 我想做的是: 1. Add an additional <select> box near Action select box 2. Add an additional action which will use the value of the added select box in step 1. 1。在“操作选择”框附近添加一个附加框 2.添加一个附加操作,

change\u list.html
具有
Action
部分,其中用户选择一个操作并将其应用于所选项目(queryset)

我想做的是:

1. Add an additional <select> box near Action select box
2. Add an additional action which will use the value of the added select box in step 1.
1。在“操作选择”框附近添加一个附加框
2.添加一个附加操作,该操作将使用步骤1中添加的选择框的值。
我试图自定义
change\u list.html
,但添加一个额外的选择框似乎相当困难


可能吗?我怎样才能做到这一点?

如果我理解正确,您想进行自定义管理操作吗

如果是这样的话,就从这个问题开始。然后看看这两个用例:

很简单:

class YourModelAdmin(admin.ModelAdmin):
    class Media:
        js = ('/static/js/adminfix.js', )

    def get_urls(self):
        urls = super(YourModelAdmin, self).get_urls()
        my_urls = patterns('',
            (r'^custom_action_select/$', self.custom_func)
        )
        return my_urls + urls

    def custom_func(self, request):
        # your action
您的adminfix.js看起来像:

(function($) {
   $(document).ready(function($) {
      $(".object-tools").append('<select id="actionid">stuff</select>');
      $(".object-tools").on('click', '#actionid', function(e){
          // you send here the request to /custom_action_select/
          // and handle if in custom_func() in your admin.py 
      });
   });
})(django.jQuery);
(函数($){
$(文档).ready(函数($){
$(“.object工具”).append('stuff');
$(“.object tools”)。在('单击','操作ID',函数(e){
//您在此处将请求发送到/custom\u action\u select/
//并在admin.py的custom_func()中处理if
});
});
})(django.jQuery);

希望这有帮助

第一个链接正是我所需要的。谢谢你的回答。但我想让选择框成为动态的。无论如何谢谢你