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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Create a class inherting from SimpleListFilter for the Sub-Category.
Inside the method
lookupscheck if inside therequest.GETthere is the matching querystring forCategory, 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)