Hey guys,
I was wondering if there is a way of making a field null vs not-null filter
without coding it yourself?
I tried:
list_filter = (('field_which_is_foreign_key', BooleanFieldListFilter),)
In the end I wrote this little one:
class MyFieldFilter(SimpleListFilter):
title = _(' field_which_is_foreign_key ')
parameter_name = ' field_which_is_foreign_key _n'
def lookups(self, request, model_admin):
return (
('T', _('Null')),
('F', _('Not Null')),
)
def queryset(self, request, queryset):
if self.value() == 'T':
return queryset.filter( field_which_is_foreign_key=None)
if self.value() == 'F':
return queryset.exclude( field_which_is_foreign_key =None)
But that's not very generic, I might need this for more fields!
Any way to do it with a bool filter?
- bram
--
http://www.samplesumo.com
http://www.freesound.org
http://www.smartelectronix.com
http://www.musicdsp.org
office: +32 (0) 9 335 59 25
mobile: +32 (0) 484 154 730
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.