Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle when overriden filter lookup separator #1352

Open
wants to merge 2 commits into
base: master
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
13 changes: 10 additions & 3 deletions drf_spectacular/contrib/django_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,16 @@ def resolve_filter_field(self, auto_schema, model, filterset_class, field_name,
suffixes = filter_field.field_class.widget.suffixes
except AttributeError:
suffixes = ['min', 'max']
field_names = [
f'{field_name}_{suffix}' if suffix else field_name for suffix in suffixes
]
# just in case widget family might be changed we check for method existence
suffixed = getattr(filter_field.field_class.widget(), "suffixed", None)
if suffixed and callable(suffixed):
field_names = [
suffixed(field_name, suffix) for suffix in suffixes
]
else: # keep default if no `suffixed` method exists on widget
field_names = [
f'{field_name}_{suffix}' if suffix else field_name for suffix in suffixes
]
explode = None
style = None
else:
Expand Down