Snippet List
Adds filtering by ranges of dates in the admin filter sidebar.
[https://github.com/coolchevy/django-datefilterspec](https://github.com/coolchevy/django-datefilterspec)
[http://coolchevy.org.ua](http://coolchevy.org.ua)
https://github.com/coolchevy/django-datefilterspec/raw/master/datefilter.png
Example:
`
from django.db import models
import datefilterspec
class Person(models.Model):
date = models.DateTimeField(default=datetime.datetime.now)
date.date_filter = True
class Admin:
list_filter = ['date']
- filter
- admin
- date
- calendar
- sidebar
- filterspec
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.
2 snippets posted so far.