Skip to content

Instantly share code, notes, and snippets.

@gomasaba
Created July 11, 2019 17:36
Show Gist options
  • Save gomasaba/0834c76f0834820921b62e62f94f3c1f to your computer and use it in GitHub Desktop.
Save gomasaba/0834c76f0834820921b62e62f94f3c1f to your computer and use it in GitHub Desktop.
BooleanDropdownFilter
# stdlib
# lib
from django.contrib.admin.filters import (
BooleanFieldListFilter,
)
# app
class BooleanDropdownFilter(BooleanFieldListFilter):
template = 'boolean_dropdown_filter.html'
{% load i18n %}
<script type="text/javascript">var go_from_select = function(opt) { window.location = window.location.pathname + opt };</script>
<h3>{% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}</h3>
<ul class="admin-filter-{{ title|cut:' ' }}">
<li>
<select class="form-control" style="width: 95%;margin-left: 2%;"
onchange="go_from_select(this.options[this.selectedIndex].value)">
{% for choice in choices %}
<option{% if choice.selected %} selected="selected"{% endif %}
value="{{ choice.query_string|iriencode }}">{{ choice.display }}</option>
{% endfor %}
</select>
</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment