convert action dropdown to buttons

parent ff017cef
// will convert admin action dropdown menu into individual buttons
// https://stackoverflow.com/questions/37318762/django-admin-display-actions-as-buttons
// modified to work on lists with more than 10 items.
(function ($) {
function fix_actions() {
var container = $('div.actions');
container.find('label, button').hide();
var buttons = $('<div></div>')
.prependTo(container)
.css('display', 'inline')
.addClass('class', 'action-buttons');
container.find('option:gt(0)').each(function () {
$('<button>')
.appendTo(buttons)
.attr('name', this.value)
.addClass('button')
.text(this.text)
.click(function () {
container.find('select')
.find(':selected').attr('selected', '').end()
.find('[value=' + this.name + ']').attr('selected', 'selected');
$('#changelist-form button[name="index"]').click();
});
});
};
$(function () {
fix_actions();
});
})(django.jQuery);
......@@ -52,6 +52,9 @@ class UrlRatingAdminInline(CompactInline):
class OrganizationAdmin(admin.ModelAdmin):
class Media:
js = ('js/action_buttons.js', )
list_display = ('name', 'type', 'country')
search_fields = (['name', 'country', 'type__name'])
list_filter = ('name', 'type__name', 'country') # todo: type is now listed as name, confusing
......@@ -92,6 +95,9 @@ class OrganizationAdmin(admin.ModelAdmin):
class UrlAdmin(admin.ModelAdmin):
class Media:
js = ('js/action_buttons.js', )
list_display = ('url', 'is_dead_reason', 'not_resolvable', 'created_on')
search_fields = ('url', )
list_filter = ('url', 'is_dead', 'is_dead_since', 'is_dead_reason',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment