数据导入出了个小bug

发布于 2022-04-28 13:28:21

1.png
2.png
数据导入寻找文件地址中的media重复了

查看更多

关注者
1
被浏览
866
liqiang
liqiang python/vue 2022-04-28
This guy hasn't written anything yet

下个版本修复

3 个回答
hongzai
hongzai 认证专家 2022-04-28
life is coding,外包,远程协助,咨询添加微信:H0nGzA1

image.png

image.png

# -*- coding: utf-8 -*-

"""
@author: 猿小天
@contact: QQ:1638245306
@Created on: 2021/8/9 009 20:48
@Remark:
"""
from rest_framework import serializers

from dvadmin.system.models import FileList
from dvadmin.utils.serializers import CustomModelSerializer
from dvadmin.utils.viewset import CustomModelViewSet


class FileSerializer(CustomModelSerializer):
    url = serializers.SerializerMethodField(read_only=True)

    def get_url(self, instance):
        return str(instance.url)

    class Meta:
        model = FileList
        fields = "__all__"

    def create(self, validated_data):
        validated_data['name'] = str(self.initial_data.get('file'))
        validated_data['url'] = self.initial_data.get('file')
        return super().create(validated_data)


class FileViewSet(CustomModelViewSet):
    """
    文件管理接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """
    queryset = FileList.objects.all()
    serializer_class = FileSerializer
    filter_fields = ['name', ]

试试这个

liqiang
liqiang python/vue 2022-04-28
This guy hasn't written anything yet

我看这个2.0.0版本导入没有问题,你这个是什么情况下的?

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览