Skip to content

Commit

Permalink
added BooleanFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jan 30, 2009
1 parent 4e87ea0 commit ac7f5fa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions filter/filters.py
@@ -1,6 +1,6 @@
from django import forms

__all__ = ['Filter', 'CharFilter']
__all__ = ['Filter', 'CharFilter', 'BooleanFilter']

class Filter(object):
creation_counter = 0
Expand All @@ -23,4 +23,6 @@ def filter(self, qs, value):

class CharFilter(Filter):
field = forms.CharField


class BooleanFilter(Filter):
field = forms.BooleanField
3 changes: 2 additions & 1 deletion filter/filterset.py
Expand Up @@ -4,7 +4,7 @@
from django.utils.datastructures import SortedDict
from django.utils.text import capfirst

from filter.filters import Filter, CharFilter
from filter.filters import Filter, CharFilter, BooleanFilter

def get_declared_filters(bases, attrs, with_base_filters=True):
filters = []
Expand Down Expand Up @@ -101,6 +101,7 @@ def filter_for_field(cls, f, name):
from django.db import models
FILTERS = {
models.CharField: CharFilter,
models.BooleanField: BooleanFilter
}
filter = FILTERS.get(f.__class__)
if filter is not None:
Expand Down
5 changes: 3 additions & 2 deletions filter/tests.py
Expand Up @@ -16,15 +16,16 @@
... model = User
>>> F.base_filters.keys()
['username', 'first_name', 'last_name', 'password']
['username', 'first_name', 'last_name', 'password', 'is_staff', 'is_active', 'is_superuser']
>>> class F(FilterSet):
... class Meta:
... model = User
... exclude = ['password']
>>> F.base_filters.keys()
['username', 'first_name', 'last_name']
['username', 'first_name', 'last_name', 'is_staff', 'is_active', 'is_superuser']
>>> class F(FilterSet):
... class Meta:
Expand Down

0 comments on commit ac7f5fa

Please sign in to comment.