Я использую несколько полей для поискового фильтра, включая FilePathField, как показано ниже:
class Entity(models.Model):
uuid = models.CharField(max_length=255, default="")
description = models.CharField(max_length=255, default="")
file = models.FilePathField(blank=False, max_length=1000, null=False)
segment_start = models.PositiveIntegerField(default=0)
class EntitySearchFilterSerializer(serializers.ModelSerializer):
class Meta:
model = Entity
fields = ('uuid', 'description', 'file', 'segment_start', )
class StandardResultsSetPagination(PageNumberPagination):
page_size = 5
page_size_query_param = 'page_size'
max_page_size = 1000
class EntitySearchList(generics.ListAPIView):
model = Entity
serializer_class = EntitySearchFilterSerializer
queryset = Entity.objects.all()
filter_backends = [filters.SearchFilter]
search_fields = ['description', ]
pagination_class = StandardResultsSetPagination
Однако при вводе только FilePathField я вижу следующую ошибку.
[19/Mar/2020 19:14:37] "GET /api/search/entity/?search=cat HTTP/1.1" 500 20295
Internal Server Error: /api/search/entity/
Traceback (most recent call last):
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 363, in fields
for key, value in self.get_fields().items():
File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 1072, in get_fields
fields[field_name] = field_class(**field_kwargs)
File "/usr/local/lib/python3.6/dist-packages/rest_framework/fields.py", line 1535, in __init__
allow_folders=allow_folders, required=required
File "/usr/local/lib/python3.6/dist-packages/django/forms/fields.py", line 1109, in __init__
for f in os.scandir(self.path):
FileNotFoundError: [Errno 2] No such file or directory: ''
Что может быть причиной этого?