Top django admin Template List

I want to override the default django admin filter template to use my own template based on this:

https://github.com/feincms/feincms/blob/master/feincms/templates/admin/filter.html

I wrote my own class SimpleListFilter, inheriting fromdjango.contrib.admin.SimpleListFilter

class PublisherStateFilter(admin.SimpleListFilter):
    title = _('Status')
    parameter_name = 'status'
    template = 'admin/blogitty/filter.html'

    [...]

This works great.

Dropdown select filter

However, I would like to use the same template for all admin filters. Is there a way to bypass all filter patterns for a given application without having to define a custom one ListFilterfor each relationship ForeignKeyand ManyToMany.

In my project blogitty. I tried both options for the DIR pattern:

blogitty/templates/admin/filter.html

and

blogitty/templates/admin/blogitty/filter.html

Bad luck: - (

Looking through the source code:

https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1030

    return TemplateResponse(request, form_template or [
        "admin/%s/%s/change_form.html" % (app_label, opts.model_name),
        "admin/%s/change_form.html" % app_label,
        "admin/change_form.html"
    ], context)

https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1569

    return TemplateResponse(request, self.change_list_template or [
        'admin/%s/%s/change_list.html' % (app_label, opts.model_name),
        'admin/%s/change_list.html' % app_label,
        'admin/change_list.html'
    ], context)

. Django ModelAdmin changeform changelist . ListFilter .

https://github.com/django/django/blob/master/django/contrib/admin/filters.py#L60

class ListFilter(object):
    title = None  
    template = 'admin/filter.html'

- TEMPLATE_DIRS:

BASE_DIR = dirname(dirname(__file__))    

TEMPLATE_DIRS = (
    join(BASE_DIR, 'templates'),
)  

cookiecutter-django Daniel Greenfeld

+4
1

class ClassFilter1(admin.ModelAdmin):
    title = 'Filter Class'
    parameter_name = 'filter-class'

    def lookups(self, request, model_admin):
       # Your Lookups

    def queryset(self, request, queryset):
       # Your Lookups

class FilterClass(admin.ModelAdmin):
    list_filter = (ClassFilter1, ClassFilter2)
    change_list_template = 'polls/change_list_template.html'

change_list_template.html .html polls/templates/polls

+2

All Articles