Skip to content

Commit

Permalink
Merge pull request #75 from pctSW1/master
Browse files Browse the repository at this point in the history
Add the ability to filter by all available fields
  • Loading branch information
miki725 authored Jan 16, 2019
2 parents ba47609 + 42fc1c3 commit f8867f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Contributors
* Ryan O’Hara - https://github.com/ryan-copperleaf
* webrunners - https://github.com/webrunners
* Simone Pellizzari - https://github.com/simone6021
* Jonathon Farzanfar - https://github.com/pctSW1
12 changes: 12 additions & 0 deletions tests/filtersets/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ class Meta(object):
'id', 'name', 'a', 'content_type', 'object_id',
}

def test_get_filters_using_all(self):
class ModelBFilterSet(ModelFilterSet):
class Meta(object):
model = ModelB
fields = '__all__'

filters = ModelBFilterSet().get_filters()

assert set(filters.keys()) == {
'id', 'name', 'a', 'content_type', 'object_id',
}

def test_get_form_field_for_field(self):
fs = ModelFilterSet()

Expand Down
5 changes: 3 additions & 2 deletions url_filter/filtersets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
'ModelFilterSetOptions',
]


LOOKUP_RE = re.compile(
r'^(?:[^\d\W]\w*)(?:{}?[^\d\W]\w*)*(?:!)?$'
r''.format(LOOKUP_SEP), re.IGNORECASE
Expand Down Expand Up @@ -54,6 +53,7 @@ class FilterSetOptions(object):
Base class for handling options passed to :class:`.FilterSet`
via ``Meta`` attribute.
"""

def __init__(self, options=None):
pass

Expand Down Expand Up @@ -436,6 +436,7 @@ class ModelFilterSetOptions(FilterSetOptions):
extra_kwargs : dict, optional
Additional kwargs to be given to auto-generated individual filters
"""

def __init__(self, options=None):
super(ModelFilterSetOptions, self).__init__(options)
self.model = getattr(options, 'model', None)
Expand Down Expand Up @@ -467,7 +468,7 @@ def get_filters(self):
''.format(name=self.__class__.__name__)
)

if self.Meta.fields is None:
if self.Meta.fields in [None, '__all__']:
self.Meta.fields = self._get_model_field_names()

state = self._build_state()
Expand Down

0 comments on commit f8867f6

Please sign in to comment.