我正在尝试实现drf-spectacular
现有的 Django REST API。
但是,尝试运行时出现以下错误
./manage.py spectacular --file schema.yml
错误:
python3.7/site-packages/django_filters/filterset.py", line 352, in get_filters
"%s" % ', '.join(undefined)
TypeError: 'Meta.fields' contains fields that are not defined on this FilterSet: client, tenant_id, subtenant_id, data_stream_id
过滤器确实有效,但似乎不能很好地与 drf-spectacular lib 配合使用。谁能建议如何解决这个问题?
规格如下:
Python 3.7.2
Django 3.0.2
django-filter 2.2.0
django-rest-framework 0.1.0
djangorestframework 3.12.1
drf-spectacular 0.12.0
视图集示例:
class subModelViewSet(viewsets.ModelViewSet):
"""Standard ViewSet for the DataStream Model."""
queryset = DataStream.objects.all()
serializer_class = DataStreamSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = ('client', 'tenant_id', 'subtenant_id', 'data_stream_id',)
序列化器示例:
class DataStreamSerializer(serializers.ModelSerializer):
"""Class to validate an uploaded DataStream."""
class Meta:
"""Nested Meta Class."""
model = DataStream
fields = '__all__'