From 769f03269dc64a48b12cf08082d30c419a7e2496 Mon Sep 17 00:00:00 2001 From: Ben Davis Date: Thu, 15 Nov 2012 23:41:05 -0600 Subject: [PATCH] Fixed issue #26 BitFieldListFilter now filters based on a "bitwise or" operation as opposed to an exact match of the bitmask. --- bitfield/admin.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bitfield/admin.py b/bitfield/admin.py index 39c835d..4bb237d 100644 --- a/bitfield/admin.py +++ b/bitfield/admin.py @@ -1,5 +1,8 @@ +from django.db.models import F +from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ from django.contrib.admin import FieldListFilter +from django.contrib.admin.options import IncorrectLookupParameters from bitfield import Bit @@ -16,6 +19,13 @@ def __init__(self, field, request, params, model, model_admin, field_path): super(BitFieldListFilter, self).__init__(field, request, params, model, model_admin, field_path) + def queryset(self, request, queryset): + filter = dict((p, F(p) | v) for p, v in self.used_parameters.iteritems()) + try: + return queryset.filter(**filter) + except ValidationError, e: + raise IncorrectLookupParameters(e) + def expected_parameters(self): return [self.lookup_kwarg]