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 %}
|
{% load i18n static %}
|
||||||
|
|
||||||
<link rel="stylesheet"
|
{% block choices %}
|
||||||
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>
|
|
||||||
|
|
||||||
<div class="filter-autocomplete">
|
<div class="filter-autocomplete">
|
||||||
<select
|
<select
|
||||||
name="{{ spec.lookup_kwarg }}"
|
name="{{ spec.lookup_kwarg }}"
|
||||||
id="id_{{ spec.lookup_kwarg }}"
|
id="id_{{ spec.lookup_kwarg }}"
|
||||||
class="admin-autocomplete"
|
class="admin-autocomplete"
|
||||||
style="width:90%;"
|
style="width:90%;"
|
||||||
data-ajax--url="{{ spec.autocomplete_url }}"
|
data-ajax--url="{{ spec.autocomplete_url }}"
|
||||||
data-app-label="{{ spec.app_label }}"
|
data-app-label="{{ spec.app_label }}"
|
||||||
data-model-name="{{ spec.model_name }}"
|
data-model-name="{{ spec.model_name }}"
|
||||||
data-field-name="{{ spec.field_name }}"
|
data-field-name="{{ spec.field_name }}"
|
||||||
data-allow-clear="true"
|
data-allow-clear="true"
|
||||||
data-placeholder="{% blocktrans with label=spec.field_label %}Search by {{ label }}…{% endblocktrans %}">
|
data-placeholder="{% blocktrans with label=spec.field_label %}Search by {{ label }}…{% endblocktrans %}">
|
||||||
{% if spec.lookup_val %}
|
{% if spec.lookup_val %}
|
||||||
<option value="{{ spec.lookup_val }}" selected>{{ spec.initial_text }}</option>
|
<option value="{{ spec.lookup_val }}" selected>{{ spec.initial_text }}</option>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
<script>
|
{% block media %}
|
||||||
(function($) {
|
{{ block.super }}
|
||||||
$('.admin-autocomplete').djangoAdminSelect2();
|
<link rel="stylesheet"
|
||||||
})(django.jQuery);
|
href="{% static 'admin/css/vendor/select2/select2.css' %}"/>
|
||||||
</script>
|
<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