diff --git a/AUTHORS.rst b/AUTHORS.rst index 9cc1e2c..ec07871 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -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 diff --git a/tests/filtersets/test_django.py b/tests/filtersets/test_django.py index 064f850..98158cc 100644 --- a/tests/filtersets/test_django.py +++ b/tests/filtersets/test_django.py @@ -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() diff --git a/url_filter/filtersets/base.py b/url_filter/filtersets/base.py index ba5bb65..d5b7246 100644 --- a/url_filter/filtersets/base.py +++ b/url_filter/filtersets/base.py @@ -25,7 +25,6 @@ 'ModelFilterSetOptions', ] - LOOKUP_RE = re.compile( r'^(?:[^\d\W]\w*)(?:{}?[^\d\W]\w*)*(?:!)?$' r''.format(LOOKUP_SEP), re.IGNORECASE @@ -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 @@ -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) @@ -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()