17

I have a model Transaction with a ForeignKey to another model (TransactionState) on state field. So in admin.py I have:

class TransactionAdmin(admin.ModelAdmin):
    ...
    list_filter = ('state', )
    ...

In TransactionState I have records like "paid", "unpaid", "delivered", "canceled", Etc. and it works fine but I want to be able to filter using checkboxes to allow multiple selection like "paid" OR "delivered". It's possible?

2
  • 2
    in the admin panel? No... not without overriding the Form and the list html template Commented Feb 12, 2015 at 22:40
  • @warath-coder yes, on the right side of the list view of the model. I'll wait to new versions, maybe will be easier in the future. Commented Feb 13, 2015 at 15:29

2 Answers 2

7
+25

For all models

You can easily override the django admin templates to customize the admin UI.

To edit the sidebar filter, just add a templates/admin/filter.html file, and write your custom HTML with radio buttons.

Note that this will change the sidebar filter for all models.

For a single model

If you want to change the filter for a single model, you can specify a template for a ListFilter:

class FilterWithCustomTemplate(admin.SimpleListFilter):
    template = "custom_template.html"

Example

As a reference example, check is the default template for filter.html.

Sign up to request clarification or add additional context in comments.

Comments

3
  1. Radio buttons cannot have multiple selection, you would need to make them check boxes.

  2. What you are looking for is making custom filters. I would suggest instead of overwriting the Filter List to contain a check form with check boxes, add a custom filter with each option as a filter. Use this link and scroll down to the SimpleListFilter and you will be able to code it with 5-10 LOC.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.