我检查了很多与此相关的帖子,但是它们不起作用,并且涉及旧版本的Django。我已经为单个文件上传创建了API。我需要一个允许上传多个(说5-10个)文件的API。
这是我的模特。
class MultipleUpload(models.Model):
file = models.FileField(blank=False, upload_to='documents/')
timestamp = models.DateTimeField(auto_now_add=True)
这是我的序列化器:
class MultipleUploadSerializer(serializers.ModelSerializer):
class Meta:
model = models.MultipleUpload
fields = '__all__'
这是我的观点:
class MultipleUploadViewset(viewsets.ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
queryset = models.MultipleUpload.objects.all()
serializer_class = serializers.MultipleUploadSerializer
parser_classes = (MultiPartParser, )