Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Stable/0.3.x: Better query parameter format introspection for BooleanFilter and DateFields #689

Open
wants to merge 1 commit into
base: stable/0.3.x
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions rest_framework_swagger/introspectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,22 @@ def build_query_parameters(self):

def build_query_parameters_from_django_filters(self):
"""
introspect ``django_filters.FilterSet`` instances.
introspect ``django_filters.filterset.BaseFilterSet`` instances.
"""
params = []
filter_class = getattr(self.callback, 'filter_class', None)
if (filter_class is not None and
issubclass(filter_class, django_filters.FilterSet)):
issubclass(filter_class, django_filters.filterset.BaseFilterSet)):
from django.forms.fields import DateField, NullBooleanField
for name, filter_ in filter_class.base_filters.items():
data_type = 'string'
data_type = 'boolean' if filter_.field_class is NullBooleanField else 'string'
data_format = 'date' if filter_.field_class is DateField else None
parameter = {
'paramType': 'query',
'name': name,
'description': filter_.label,
}
normalize_data_format(data_type, None, parameter)
normalize_data_format(data_type, data_format, parameter)
multiple_choices = filter_.extra.get('choices', {})
if multiple_choices:
parameter['enum'] = [choice[0] for choice
Expand Down