djangodjango-admin

django admin list_filter too long


I have a list_filter with loads of sectors. This list, on the right side of the page, is too long.

Can I use an input select field instead since I can't choose more than one sector?

I have seen this before, screenshots, but I can not find the way to do this.

edit:

I have a custom FilterSpec not a list_filter


Solution

  • This is how i resolved it (jQuery):

     $('#changelist-filter ul').each(function(){
    
            var maxlength = 10;
    
            if ($(this).children().length > maxlength )
            {
                var list=$(this),
                    select=$(document.createElement('select')).insertBefore($(this).hide());
    
                $('>li a', this).each(function(){
                    console.log($(this).parent().attr('class'));
    
                    var target=$(this).attr('target'),
                        option=$(document.createElement('option'))
                            .appendTo(select)
                            .val(this.href)
                            .attr('selected', $(this).parent().attr('class'))
                            .html($(this).html())
                            .click(function(){
                                if (target==='_blank'){
                                    window.open($(this).val());
                                }
                                else{
                                    window.location.href=$(this).val();
                                }
                            });
                });
                list.remove();
    
            }
        });