У меня есть приложение upload в моем проекте django, которое состоит из кода ниже
models.py
class File(models.Model):
file = models.FileField(blank=False, null=True, upload_to =file_directory_path)
def __str__(self):
return self.file.name
serialisers.py
class FileSerializer(serializers.ModelSerializer):
file = serializers.FileField()
class Meta:
model = File
fields = '__all__'#('file')
def to_representation(self, instance):
representation = super().to_representation(instance)
file = {
"url": representation.pop("file"),
"size": instance.file.size,
"name": instance.file.name,
#"date": instance.file.date,
}
representation['file'] = file
return representation
views.py
class FileUploadView(APIView):
parser_class = (FileUploadParser,)
def post(self, request, *args, **kwargs):
file_serializer = FileSerializer(data=request.data)
if file_serializer.is_valid():
file_serializer.save()
return Response(file_serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
urls.py
router = routers.DefaultRouter()
router.register('api/upload', FileViewSet, 'upload')
router.register('api/file', FileViewSet, 'file')
urlpatterns = router.urls
When, i GET список по url / api / upload / или / api / upload / it возвращает ошибку: AssertionError в / api / upload / AutoFilterSet разрешил поле 'file' с 'точным' поиск неизвестного типа поля FileField. Попробуйте добавить переопределение в "Meta.filter_overrides".