python - Django Admin: Numeric field filter -
how create filter numeric data in django admin range inputs?
p.s. found similar question, here suggest how group concrete ranges , last question activity 2 years ago.
django admin: how filter on integer field specific range of values
warning! parts of api django, mentioned in answer, considered internal , may changed in future releases of django without notification.
taking note mind, pretty easy create own filter. need is:
- subclass
simplelistfilter, create method inside generate default range values , selected range values (for rendering template filter) - set queryset method take parameters submitted filter , filter list queryset
- create template filter (based on admin/filter.html)
- set
templateproperty insimplelistfiltersubclass, pointing filter template.
django pass template 3 parameters:
title- filter title (takentitleproperty in class)choices- list of dicts generatedchoicesmethod of class (by default modifies list of tuples returnedlookupsmethod)spec- class instance.
from point, can attribute or method of class, using spec in template, creation of filter should possible.
Comments
Post a Comment