def get_filter_fields(self, path, method, view): if not schemas.is_list_view(path, method, view): return [] if not getattr(view, 'filter_backends', None): return [] fields = [] for filter_backend in view.filter_backends: backend = filter_backend() if not hasattr(backend, 'get_filterset_class'): fields += filter_backend().get_schema_fields(view) continue filter_class = backend.get_filterset_class(view, view.get_queryset()) if not filter_class: continue for filter_name, filter_instance in filter_class().filters.items(): filter_type = get_field_type(filter_instance) field = coreapi.Field( name=filter_name, required=False, location=filter_type, ) # Prevent double rendering if field not in fields: fields.append(field) return fields
def show_filter_backends(path, method, view): """Return True if view have an explicitly defined parameter `show_filter_backends`, which we can inspect or the given path/method appears to represent a list view. """ if getattr(view, 'show_filter_backends', None): return True return is_list_view(path, method, view)