Skip to content

Commit

Permalink
Use DRF BooleanFilter for NullBooleanField (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarPersson authored and carltongibson committed Jul 13, 2018
1 parent 6e8456a commit dbbae86
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions django_filters/rest_framework/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
FILTER_FOR_DBFIELD_DEFAULTS.update({
models.DateTimeField: {'filter_class': IsoDateTimeFilter},
models.BooleanField: {'filter_class': BooleanFilter},
models.NullBooleanField: {'filter_class': BooleanFilter},
})


Expand Down
1 change: 1 addition & 0 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class User(models.Model):
status = models.IntegerField(choices=STATUS_CHOICES, default=0)

is_active = models.BooleanField(default=False)
is_employed = models.NullBooleanField(default=False)

favorite_books = models.ManyToManyField('Book', related_name='lovers')

Expand Down
6 changes: 6 additions & 0 deletions tests/rest_framework/test_filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def test_booleanfilter_widget(self):
self.assertIsInstance(result, filters.BooleanFilter)
self.assertEqual(result.extra['widget'], BooleanWidget)

def test_booleanfilter_widget_nullbooleanfield(self):
field = User._meta.get_field('is_employed')
result = FilterSet.filter_for_field(field, 'is_employed')
self.assertIsInstance(result, filters.BooleanFilter)
self.assertEqual(result.extra['widget'], BooleanWidget)


@skipIf(is_crispy(), 'django_crispy_forms must be installed')
@override_settings(INSTALLED_APPS=settings.INSTALLED_APPS + ('crispy_forms', ))
Expand Down

0 comments on commit dbbae86

Please sign in to comment.