Opened 5 years ago

Closed 3 years ago

Last modified 3 years ago

#16380 closed New feature (fixed)

admin_list_filter should pass the spec to the template

Reported by: hvdklauw Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: bruno@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no


If the admin_list_filter inclusion tag also passed the spec object to the admin/filter.html template we could write custom filterspec's that have attributes that influence the way the filterspec is displayed (in a dropdown with javascript for instance).

Right now you have to override the change_list.html, and create your own template tag to do this and then still override the admin/filter.html to actually change how it's displayed.

Attachments (1)

16380.diff (613 bytes) - added by hvdklauw 5 years ago.

Download all attachments as: .zip

Change History (9)

Changed 5 years ago by hvdklauw

comment:1 Changed 5 years ago by hvdklauw

  • Easy pickings set
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by jezdez

  • Easy pickings unset
  • Needs documentation set
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

While this is an interesting idea, this needs an actual example and tests.

comment:3 Changed 5 years ago by hvdklauw

Example admin/filter.html

{% load i18n %}
<h3>{% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}</h3>
{% if spec.field.related and choices|length > 5 %}
<select class="filter_choice">
    {% for choice in choices %}
        <option value="{{ choice.query_string|iriencode }}"{% if choice.selected %} selected='selected'{% endif %}>{{ choice.display|safe }}</option>
    {% endfor %}
{% else %}
{% for choice in choices %}
    <li{% if choice.selected %} class="selected"{% endif %}>
    <a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li>
{% endfor %}
{% endif %}

And this little bit of javascript somewhere on document.ready:

$(".filter_choice").change(function() {
          location.href = $(this).val();

comment:4 Changed 5 years ago by jezdez

Nice! Let's put something like that in the docs.

comment:5 Changed 5 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

comment:6 Changed 3 years ago by bruno@…

  • Cc bruno@… added

This ticket could be closed, admin_list_filter is now (in v1.6 at least) a simple_tag that uses the spec's template AND pass the spec to the template (cf line 409).

comment:7 Changed 3 years ago by bmispelon

  • Resolution set to fixed
  • Status changed from new to closed


Thanks for digging up these old out-of-date tickets
FYI, you don't need special permmissions to close a ticket here and you can do so yourself.

Putting the commit id in the comment when you close a ticket will help us double check.

In this case, this issue appears to have been fixed in 4dbeb4bca4638ff851a2f4844d262dbe1652f7b5.


comment:8 Changed 3 years ago by bruno@…

@bmispelon: ok will do next time.

Note: See TracTickets for help on using tickets.
Back to Top