-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Labels
Description
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.
mrsarm, thibaut-pro, goetzb and PeKne