Jahongir Rahmonov
Jahongir Rahmonov

Reputation: 13763

Customize change_list.html in django admin

change_list.html has Action part where a user selects an action and applies it on the selected items(queryset).

What I am trying to do is the following:

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.

I tried to customize change_list.html but adding an additional select box seemed quite difficult.

Is it possible? How can I do this?

Upvotes: 0

Views: 915

Answers (2)

doniyor
doniyor

Reputation: 37924

it is simple:

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

and your adminfix.js would look like:

(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);

hope this helps

Upvotes: 1

belteshazzar
belteshazzar

Reputation: 2213

If I understand you correctly, you want to make a custom Admin Action?

If so, start with the Django documentation for it. Then Have a look at these two use cases:

Upvotes: 1

Related Questions