I am getting error while trying to upload files through POSTMAN here is the error and it is 26,000+ long. Although the uploaded files are being uploaded to the directory just fine but the return response is not . Any idea how to solve this?
Uploaded media
my models.py
from django.db import models
class Photo(models.Model):
image = models.ImageField(upload_to='images/')
class Audio(models.Model):
audio = models.FileField(upload_to='audios/')
class Video(models.Model):
video = models.FileField(upload_to='videos/')
my serializers.py
from rest_framework import serializers
from .models import Photo, Audio
from rest_framework import status
from rest_framework.response import Response
class ImageListSerializer(serializers.Serializer):
image = serializers.ListField(
child=serializers.FileField(max_length=100, allow_empty_file=False, use_url=True))
def create(self, validated_data):
image=validated_data.pop('image')
for img in image:
photo=Photo.objects.create(image=img)
print(photo)
return photo
class Meta:
model = Photo
fields = ('pk', 'image')
class AudioListSerializer(serializers.Serializer):
audio = serializers.ListField(
child=serializers.FileField(max_length=100, allow_empty_file=False, use_url=True))
def create(self, validated_data):
audio=validated_data.pop('audio')
for aud in audio:
sound=Audio.objects.create(audio=aud,**validated_data)
print (sound)
return sound
class Meta:
model = Audio
fields = ('pk', 'audio')
my views.py
from django.shortcuts import render
from rest_framework import viewsets, mixins, status
from rest_framework.settings import api_settings
from .models import Photo, Audio
from .serializers import ImageListSerializer, AudioListSerializer
from rest_framework.parsers import MultiPartParser, FormParser
from rest_framework.response import Response
class PhotoViewSet(viewsets.ModelViewSet):
serializer_class = ImageListSerializer
parser_classes = (MultiPartParser, FormParser,)
queryset = Photo.objects.all()
class AudioViewSet(viewsets.ModelViewSet):
serializer_class = AudioListSerializer
parser_classes = (MultiPartParser, FormParser,)
queryset = Audio.objects.all()
question from:
https://stackoverflow.com/questions/65680192/getting-a-huge-null-list-on-response-while-trying-to-upload-through-drf 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…