我设法解决了这个问题,希望对社区有所帮助
serializers.py:
class FileListSerializer ( serializers.Serializer ) : image = serializers.ListField( child=serializers.FileField( max_length=100000, allow_empty_file=False, use_url=False ) ) def create(self, validated_data): blogs=Blogs.objects.latest('created_at') image=validated_data.pop('image') for img in image: photo=Photo.objects.create(image=img,blogs=blogs,**validated_data) return photoclass PhotoSerializer(serializers.ModelSerializer): class meta: model = Photo read_only_fields = ("blogs",)
views.py:
class PhotoViewSet(viewsets.ModelViewSet): serializer_class = FileListSerializer parser_classes = (MultiPartParser, FormParser,) queryset=Photo.objects.all()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)