Features: 1) Refactor autocomplete filter template to use {% block %} structure for better modularity; 2) Include {% block media %} for styles and scripts management.
Fixes: 1) Resolve potential redundancy in script and CSS inclusion. Extra: Simplify and streamline the template by removing inline `<script>` tags and consolidating structure.
This commit is contained in:
parent
b70f5601e7
commit
d4156f88ab
1 changed files with 23 additions and 24 deletions
|
|
@ -1,34 +1,33 @@
|
|||
{% extends "admin/filter.html" %}
|
||||
{% load i18n static %}
|
||||
|
||||
<link rel="stylesheet"
|
||||
href="{% static 'admin/css/vendor/select2/select2.css' %}"/>
|
||||
<link rel="stylesheet"
|
||||
href="{% static 'admin/css/autocomplete.css' %}"/>
|
||||
|
||||
<script src="{% static 'admin/js/jquery.init.js' %}"></script>
|
||||
<script src="{% static 'admin/js/vendor/select2/select2.full.js' %}"></script>
|
||||
<script src="{% static 'admin/js/autocomplete.js' %}"></script>
|
||||
|
||||
{% block choices %}
|
||||
<div class="filter-autocomplete">
|
||||
<select
|
||||
name="{{ spec.lookup_kwarg }}"
|
||||
id="id_{{ spec.lookup_kwarg }}"
|
||||
class="admin-autocomplete"
|
||||
style="width:90%;"
|
||||
data-ajax--url="{{ spec.autocomplete_url }}"
|
||||
data-app-label="{{ spec.app_label }}"
|
||||
data-model-name="{{ spec.model_name }}"
|
||||
data-field-name="{{ spec.field_name }}"
|
||||
data-allow-clear="true"
|
||||
data-placeholder="{% blocktrans with label=spec.field_label %}Search by {{ label }}…{% endblocktrans %}">
|
||||
name="{{ spec.lookup_kwarg }}"
|
||||
id="id_{{ spec.lookup_kwarg }}"
|
||||
class="admin-autocomplete"
|
||||
style="width:90%;"
|
||||
data-ajax--url="{{ spec.autocomplete_url }}"
|
||||
data-app-label="{{ spec.app_label }}"
|
||||
data-model-name="{{ spec.model_name }}"
|
||||
data-field-name="{{ spec.field_name }}"
|
||||
data-allow-clear="true"
|
||||
data-placeholder="{% blocktrans with label=spec.field_label %}Search by {{ label }}…{% endblocktrans %}">
|
||||
{% if spec.lookup_val %}
|
||||
<option value="{{ spec.lookup_val }}" selected>{{ spec.initial_text }}</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
<script>
|
||||
(function($) {
|
||||
$('.admin-autocomplete').djangoAdminSelect2();
|
||||
})(django.jQuery);
|
||||
</script>
|
||||
{% block media %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet"
|
||||
href="{% static 'admin/css/vendor/select2/select2.css' %}"/>
|
||||
<link rel="stylesheet"
|
||||
href="{% static 'admin/css/autocomplete.css' %}"/>
|
||||
|
||||
<script src="{% static 'admin/js/vendor/select2/select2.full.js' %}"></script>
|
||||
<script src="{% static 'admin/js/autocomplete.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue