Opened 13 years ago

Closed 10 years ago

Last modified 10 years ago

#16380 closed New feature (fixed)

admin_list_filter should pass the spec to the template

Reported by: Harro Owned by: nobody
Component: contrib.admin Version: dev
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

Description

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 Harro 13 years ago.

Download all attachments as: .zip

Change History (9)

by Harro, 13 years ago

Attachment: 16380.diff added

comment:1 by Harro, 13 years ago

Easy pickings: set
Has patch: set

comment:2 by Jannis Leidel, 13 years ago

Easy pickings: unset
Needs documentation: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

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

comment:3 by Harro, 13 years ago

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 %}
</select>
{% else %}
<ul>
{% for choice in choices %}
    <li{% if choice.selected %} class="selected"{% endif %}>
    <a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li>
{% endfor %}
</ul>
{% endif %}

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

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

comment:4 by Jannis Leidel, 13 years ago

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

comment:5 by Jacob, 13 years ago

milestone: 1.4

Milestone 1.4 deleted

comment:6 by bruno@…, 10 years ago

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 https://github.com/django/django/blob/master/django/contrib/admin/templatetags/admin_list.py line 409).

comment:7 by Baptiste Mispelon, 10 years ago

Resolution: fixed
Status: newclosed

Hi,

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.

Thanks.

comment:8 by bruno@…, 10 years ago

@bmispelon: ok will do next time.

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