Group results by a range of values in admin sidebar
Adds filtering by ranges of values in the admin filter sidebar. This allows rows in numerical fields to be grouped together (in this case, group by price): By store price All < 100 100 - 200 200 - 500 500 - 2000 >= 200 **To use:** 1. save the code as rangevaluesfilterspec.py in your app's directory 2. add `import rangevaluesfilterspec` to your models.py 3. add `myfield.list_filter_range = [value1, value2, ...]` to your filter field **Example:** from django.db import models import rangevaluesfilterspec class Product(models.Model): store_price = models.DecimalField(max_digits=10, decimal_places=2) store_price.list_filter_range = [100, 200, 500, 2000] class Admin: list_filter = ['store_price'] Note that two extra groups are added: less-than the lowest value, and greater-than-or-equal-to the highest value.
- filter
- admin
- sidebar