Skip to content

Django2 now supports AutoComplete via select2, can django-admin-list-filter-dropdown? #7

@macolo

Description

@macolo

The Autocomplete URL can be retrieved via a template tag:

register = template.Library()

@register.simple_tag(takes_context=True)
def get_autocomplete_url(context):
    spec = context.get('spec')
    app_label = spec.field.related_model._meta.app_label
    model_name = spec.field.related_model._meta.model_name

    return reverse('admin:{}_{}_autocomplete'.format(
        app_label,
        model_name,
    ))

The problem is to insert admin/js/vendor/select2/select2.full.js after admin/js/vendor/jquery/jquery.js but before /static/admin/js/jquery.init.js which enables noConflict for jQuery and hides jQuery from the global scope (which select2 needs). The filter's __init__ gets ModelAdmin instance passed, however its Media instance cannot be changed at this point. The only option I found is extending the admin's change_list.html template, which adds complexity to the module (needs to be inserted before django.contrib.admin in INSTALLED_APPS.

It works, but its far from being modular.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions