Я прилагаю код ... models.py:
class File(models.Model):
file = models.FileField(blank=False, null=False)
print("wat is the name",file)
def __str__(self):
return self.file.name`
serializers.py:
class FileSerializer(serializers.ModelSerializer):
#file = serializers.FileField(use_url=False)
class Meta:
model = File
fields = "__all__"`
views.py:
class MyModelView(generics.ListAPIView):
parser_classes = (MultiPartParser,FormParser)
serializer_class = FileSerializer
@action(detail=False, methods=['post'], name='Uploader View', parser_classes=[multipartparser],)
@api_view(['POST'])
def post(self, request, *args, **kwargs):
"""
Create a MyModel
---
summary: Uploads a file.
requestBody:
content:
multipart/form-data:
consumes:
- multipart/form-data
parameters:
- in: formData
name: file
"paramType": "formData",
"dataType": "file",
type: File
responseMessages:
- code: 201
message: Created
"""
file_serializer = FileSerializer(data=request.data)
return Response(file_serializer.data, status=status.HTTP_201_CREATED)
Пожалуйста скажите, какие изменения требуются в моем коде !!! Спасибо.