djangosnippets.org: Latest snippets tagged with 'filterspec'https://djangosnippets.org/tags/filterspec/2011-05-07T16:11:16.439498-05:00FilterSpec for ForeignKeys to auth.User with HTML input tag for ModelAdmin.list_filter
2011-05-07T16:11:16.439498-05:00loichttps://djangosnippets.org/snippets/2429/<p>I often need to filter my change_list by author but my User table is usually pretty crowded and adding the User FK to list_filter would end up with hundreds of user links in the sidebar. This snippets replace those hundreds of links by a simple HTML <input>.</p>
Freely redistributableGroup results by a range of dates in admin sidebar with calendar
2011-01-31T18:14:46.867927-06:00coolchevyhttps://djangosnippets.org/snippets/2344/<p>Adds filtering by ranges of dates in the admin filter sidebar.</p>
<p><a href="https://github.com/coolchevy/django-datefilterspec">https://github.com/coolchevy/django-datefilterspec</a></p>
<p><a href="http://coolchevy.org.ua">http://coolchevy.org.ua</a></p>
<p>https://github.com/coolchevy/django-datefilterspec/raw/master/datefilter.png</p>
<p>Example:</p>
<p>`
from django.db import models
import datefilterspec
class Person(models.Model):
date = models.DateTimeField(default=datetime.datetime.now)
date.date_filter = True</p>
<p>class Admin:
list_filter = ['date']</p>
Freely redistributableRelatedNullFilterSpec: django-admin custom filter all/null/not null/choices
2010-10-07T14:30:59.132524-05:00Codekohttps://djangosnippets.org/snippets/2229/<p>A simple django-admin filter to replace standar RelatedFilterSpec with one with the "All"/"Null"/"Not null" options.
It applies to all relational fields (ForeignKey, ManyToManyField).
</p>
<p>You can put the code in the <code>__init__.py</code> or wherever you want.
</p>
<p>The <code>_register_front</code> idea is copied on <a href="http://djangosnippets.org/snippets/1963/">this snippet</a>
</p>
Freely redistributableForeignKey filterspec
2010-09-13T09:32:31.406677-05:00luc_jhttps://djangosnippets.org/snippets/2194/<p>Unfortunately, it is not possible currently to use foreign keys in list filter of the admin website. list_filter=['city__country'] doesn't work.</p>
<p>This filter spec tries to workaround this problem.</p>
<p>It is also possible to have 2 filters for a foreign-key field but it requires to add a dummy field to the …</p>
Freely redistributabledjango-admin custom filter: IS NULL/IS NOT NULL
2010-03-18T20:16:27.258751-05:00Eloffhttps://djangosnippets.org/snippets/1963/<p>A simple django-admin filter to allow a boolean-like filter for IS NULL/IS NOT NULL.
</p>
<p>By default it applies to CharField, IntegerField, and FileField, but you can change this by editing NullFilterSpec.fields.
</p>
Freely redistributableForeign Key list_filter wthout custom FilterSpec
2010-02-04T20:18:00.520074-06:00haileris23https://djangosnippets.org/snippets/1911/<p>This is some (probably) pretty dodgy code that allows for foreign keys in the admin's list_filter without using a custom FilterSpec. It overrides the django.db.models.options.Options get_field class to handle spanned relationships, i.e. list_filter=('house<strong>room</strong>town',) as seen in http://code.djangoproject.com/ticket/3400
</p>
<p>I have only tested this with a double foreign key relationship('house__room'), …</p>
Freely redistributableadmin filters as select boxes
2009-10-13T17:40:52.106833-05:00gzyhttps://djangosnippets.org/snippets/1758/<p>This templatetag let's you output a form with select boxes instead of the ul's for filters.
Uses some hacks to get the param names out of query strings.
</p>
<p>This would be a lot easier if filterspecs defined params instead of query strings
(if filter tag would handle the encoding)
</p>
Freely redistributableAlphabetic filter for admin
2008-09-12T13:55:52.502434-05:00sementehttps://djangosnippets.org/snippets/1051/<p>This snippet is based on <a href="http://www.djangosnippets.org/snippets/748/">#748</a>.</p>
<p>Adds filtering by first char (alphabetic style) of values in the admin
filter sidebar. The example below results in this filter:</p>
<pre><code>By name that starts with
All
A
B
G
M
X
</code></pre>
<p>urls.py example (only for register the filter):</p>
<pre><code>import <your project>.admin.filterspecs
</code></pre>
<p>models.py …</p>
Freely redistributable