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 9215667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:15:19+00:00 2026-06-18T02:15:19+00:00

in the list filter of a model in my Django admin I have a

  • 0

in the list filter of a model in my Django admin I have a filter Category, and I would like to add a filter Sub-category, which values depend on the selected Category value.

How can I achieve this using ModelAdmin.list_filter?

Thank you

  • 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-06-18T02:15:20+00:00Added an answer on June 18, 2026 at 2:15 am

    Create a class inherting from SimpleListFilter for the Sub-Category.

    Inside the method lookups check if inside the request.GET there is the matching querystring for Category, if there is, make a queryset based on this filter.

    Should look something like that: (change according to your real models..might have syntax error, I didn’t test the code, but it should look very similar)

    class SubCategoryFilter(SimpleListFilter):
        title = 'sub category'
        parameter_name = 'sub_category'
    
        def lookups(self, request, model_admin):
            sub_categories = Category.objects;
            if 'category' in request.GET:
                 sub_categories = sub_categories.filter(main_category=request.GET['category'])
            return (
                (sub_cat.pk,sub_cat.text) for sub_cat in sub_categories
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django application which has two models like this: class MyModel(models.Model): name
How can I add a custom filter to django admin (the filters that appear
I would like after insert in django admin create a directory like a record
I have a Django Model that implements a time range, like this: class Period(models.Model):
I would like to know how to filter a django query set by a
I have a simple Django model like: class Person(models.Model): referrer = models.ForeignKey('self', null=True) ...
I have a Django model containing a text field. In the admin GUI, I'd
So I have a few Django models that look like this: class City(models.Model): name
I have a list filter = ['a', 'b', 'c']. I need to frame the
I'd like to use django list_filter to filter by some enum value. Due to

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.