Can Django admin site select entries by a custom date range, i.e. using two DateFields
with AdminDateWidget
? I know that there are date_hierarchy
and list_filter
properties, but they don't seem very useful when there are a lot of DB entries and you just need to filter items by exact date__gte
and date__lte
query.
views:
555answers:
1
+3
A:
This functionality isn't provided as far as I'm aware, but you can build it yourself.
Firstly, you can filter items using date__gte
and date__lte
as GET arguments in the url.
For example
/admin/myapp/bar/?date__gte=2009-5-1&date__lt=2009-8-1
will display all bar objects with dates in May, June or July 2009.
Then if you override the admin/change_list.html template file, you can add widgets for start and end dates, which navigate to the required url.
Hat tip to Daniel's answer to another SO question, which taught me about using queryset filter parameters as GET arguments.
Alasdair
2009-11-03 21:28:55
Thanks a lot, very useful feature.
Dmitry Gladkov
2009-11-04 16:52:52