Skip to content

Commit

Permalink
Fixed issue #26
Browse files Browse the repository at this point in the history
BitFieldListFilter now filters based on a "bitwise or" operation as opposed to
an exact match of the bitmask.
  • Loading branch information
bendavis78 committed Nov 16, 2012
1 parent cd7d894 commit 769f032
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bitfield/admin.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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]

Expand Down

0 comments on commit 769f032

Please sign in to comment.