Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6100109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:20:55+00:00 2026-05-23T13:20:55+00:00

List_filter labels for foreign key filters in django admin are always ordered by id

  • 0

List_filter labels for foreign key filters in django admin are always ordered by id and that can cause a pretty mess when there are many filters in the list.

I have been searching for simple solution how to order those labels alphabetically or by date for some time now. It seemed that besides of using FilterSpec there is no solution for it.

Until I did this.

I have changed the template for filter.html (put it in admin folder in your templates directory) so it looks like this (found it somewhere on django snippets I guess):

{% load i18n %}
<h3>{% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}</h3>
<div align="right">
  <select onChange="javascript:window.location = this.options[this.selectedIndex].value;" style="width: 80%">
    {% for choice in choices %}
      <option {% if choice.selected %}selected{% endif %} value="{{ choice.query_string|iriencode }}">
        {{ choice.display }}
      </option>
    {% endfor %}
  </select>
</div>

And then I used ‘dictsort:”name”‘ template tag on for loop so the template finally looked like this:

{% load i18n %}
<h3>{% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}</h3>
<div align="right">
  <select onChange="javascript:window.location = this.options[this.selectedIndex].value;" style="width: 80%">
    {% for choice in choices|dictsort:"display" %}
      <option {% if choice.selected %}selected{% endif %} value="{{ choice.query_string|iriencode }}">
        {{ choice.display }}
      </option>
    {% endfor %}
  </select>
</div>

I have used select drop-down since I had many labels, but it can be used on the standard ‘ul’ list too. Now I finally have all my foreign key based filters ordered alphabetically (and it works even if using dates).

If you need reversed dosting there is dictsortreversed template tag for that.

Hope that this helps someone.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:20:56+00:00Added an answer on May 23, 2026 at 1:20 pm

    Errr, the question itself contains the answer. Sorry for not structuring it better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a form that allows a user to filter a list with by
List Comprehension for me seems to be like the opaque block of granite that
List Comprehension is a very useful code mechanism that is found in several languages,
List comprehensions can be useful in certain situations, but they can also be rather
Consider: List<String> someList = new ArrayList<>(); // add "monkey", "donkey", "skeleton key" to someList
Any list of Testing frameworks for ActionScript 2.0/3.0 around there?
First a little background: I have an Event model that has various event_type s.
Device is a Xoom Tablet. For some reason I can't do a HttpPost, when
The Python list comprehension syntax makes it easy to filter values within a comprehension.
I'm implementing a textbox filter on a list based on Josh Smith's example at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.