我正在尝试在一个字段中上传多个文件或图像。它返回一个图像/文件,但不返回多个对象。
我尝试在序列化器中传递many = True。数据库中仅保存一个图像/文件。
型号:
class FoundationImage(models.Model):
project_name = models.ForeignKey(Project,on_delete=models.DO_NOTHING)
site_clearing = models.ImageField(upload_to='images/%Y/%m/%d/')
def __str__(self):
return str(self.project_name)
观看次数:
class FoundationImageViewSet(DefaultsMixin, viewsets.ModelViewSet):
queryset = FoundationImage.objects.order_by('created_at')
serializer_class = FoundationImageSerializer
序列化器
class FoundationImageSerializer(serializers.ModelSerializer):
class Meta:
model = FoundationImage
fields = ('__all__')
{ “ id”:2 “ setting_site_clearing”:“ http://127.0.0.1:8000/media/images/2019/05/22/ck.jpeg” }
预期输出应在该字段中包含多张图片