Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test_project/one_to_one/fixtures/one_to_one.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,12 @@
"name": "Steve"
},
"pk": 3
},
{
"model": "one_to_one.waiter",
"fields": {
"name": "Michal"
},
"pk": 4
}
]
2 changes: 1 addition & 1 deletion test_project/one_to_one/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __str__(self):

@six.python_2_unicode_compatible
class Waiter(models.Model):
restaurant = models.ForeignKey(Restaurant)
restaurant = models.ForeignKey(Restaurant, null=True)
name = models.CharField(max_length=50)

def __str__(self):
Expand Down
14 changes: 14 additions & 0 deletions tests/filtersets/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,17 @@ def _test(fs, data, qs, expected, count):
.exclude(name__icontains='jon')),
1
)
_test(
WaiterFilterSet,
'restaurant__isnull=True',
Waiter.objects.all(),
Waiter.objects.filter(restaurant__isnull=True),
1
)
_test(
WaiterFilterSet,
'restaurant__isnull=False',
Waiter.objects.all(),
Waiter.objects.filter(restaurant__isnull=False),
3
)
2 changes: 1 addition & 1 deletion url_filter/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

LOOKUP_FIELD_OVERWRITES = {
'isnull': forms.BooleanField(),
'isnull': forms.BooleanField(required=False),
'second': forms.IntegerField(min_value=0, max_value=59),
'minute': forms.IntegerField(min_value=0, max_value=59),
'hour': forms.IntegerField(min_value=0, max_value=23),
Expand Down
10 changes: 9 additions & 1 deletion url_filter/filtersets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

__all__ = ['FilterSet', 'FilterSetOptions', 'StrictMode']

FK_FIELD_FILTERS = {
'isnull',
}


class StrictMode(enum.Enum):
"""
Expand Down Expand Up @@ -154,6 +158,7 @@ def _init(self, data=None, queryset=None, context=None,
self.queryset = queryset
self.context = context or {}
self.strict_mode = strict_mode
self._given_lookups = None

def repr(self, prefix=''):
header = '{name}()'.format(name=self.__class__.__name__)
Expand Down Expand Up @@ -347,7 +352,10 @@ def get_spec(self, config):
value = LookupConfig(config.key, config.data)

if name not in self.filters:
raise SkipFilter
if name in FK_FIELD_FILTERS:
return super(FilterSet, self).get_spec(config)
else:
raise SkipFilter

return self.filters[name].get_spec(value)

Expand Down