Created
January 20, 2011 15:47
-
-
Save jaymzcd/788077 to your computer and use it in GitHub Desktop.
A filterspec to attach to your models for showing __isnull fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NoneFilterSpec(ChoicesFilterSpec): | |
| """Filters based on a field being either None or populated """ | |
| def __init__(self, f, request, params, model, model_admin): | |
| super(NoneFilterSpec, self).__init__(f, request, params, model, model_admin) | |
| self.lookup_kwarg = '%s__isnull' % f.name | |
| self.lookup_val = request.GET.get(self.lookup_kwarg, None) | |
| self.lookup_choices = [True, False] | |
| self.lookup_choices.sort() | |
| def choices(self, clist): | |
| yield { | |
| 'selected': self.lookup_val is None, | |
| 'query_string': cl.get_query_string({}, [self.lookup_kwarg]), | |
| 'display': _('All') | |
| } | |
| for val in self.lookup_choices: | |
| yield { | |
| 'selected': smart_unicode(val) == self.lookup_val, | |
| 'query_string': clist.get_query_string({self.lookup_kwarg: val}), | |
| 'display': repr(val) | |
| } | |
| def title(self): | |
| return _('%(field_name)s that is empty') % {'field_name': self.field.verbose_name} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment