Django Admin: Numeric field filter
<p>How to create filter for numeric data in Django Admin with range inputs?</p>

<p>P.S. Found only this similar question, but here suggest only how to group by concrete ranges and last question activity was 2 years ago.</p>

<p><a href="http://stackoverflow.com/questions/4060396/django-admin-how-do-i-filter-on-an-integer-field-for-a-specific-range-of-values">Django Admin: How do I filter on an integer field for a specific range of values</a></p>

<p><strong>Warning!</strong> Some parts of API from django, mentioned in my answer, are considered internal and may be changed in future releases of django without any notification.</p>

<p>Taking that note to your mind, it is actually pretty easy to create your own filter. All you need to do is:</p>

<ol>
<li>subclass <code>SimpleListFilter</code> and create some method inside that will generate your default range values and selected range values (for rendering template with your filter)</li>
<li>Set queryset method that will take parameters submitted by your filter and filter list queryset</li>
<li>create template with your filter (based on <a href="https://github.com/django/django/blob/stable/1.10.x/django/contrib/admin/templates/admin/filter.html" rel="nofollow">admin/filter.html</a>)</li>
<li>set <code>template</code> property in your <code>SimpleListFilter</code> subclass, pointing to your filter template.</li>
</ol>

<p>Django will pass to your template 3 parameters:</p>

<ul>
<li><code>title</code> - your filter title (taken from <code>title</code> property in your class)</li>
<li><code>choices</code> - list of dicts generated by <code>choices</code> method of your class (by default it modifies list of tuples returned by <code>lookups</code> method)</li>
<li><code>spec</code> - your class instance.</li>
</ul>

<p>From that point, you can get to any attribute or method of your class, using <code>spec</code> in template, so creation of any filter should be possible.</p>

python django django-admin