• other Tank


    app下创建fixtures目录,在里面创建mydata.json文件或者mydata.YAML格式文件(文件名没有强制规定),里面填写你要添加的数据,大致如下

    [
      {
        "model": "card.WeekType",
        "pk": "1",
        "fields": {
          "week_day": "monday",
          "zh_hans": "周一"
        }
      },
      {
        "model": "card.WeekType",
        "pk": "2",
        "fields": {
          "week_day": "tuesday",
          "zh_hans": "周二"
        }
      }
    ]
    

    调用: python3 manage.py loaddata mydata

    他会搜寻每个app下的fixtures目录中是否存在mydata的文件,存在即会加载里面的数据。

    查看序列化器的信息

    from apps.card.serializers.card_serializer import DiscountRuleSerializer
    >>> a = DiscountRuleSerializer()
    >>> print(repr(a))
    DiscountRuleSerializer():
        id = IntegerField(label='ID', read_only=True)
        st_time = TimeField(format='%H:%M:%S')
        end_time = TimeField(format='%H:%M:%S')
        create_time = DateTimeField(label='创建时间', read_only=True)
        update_time = DateTimeField(label='更新时间', read_only=True)
        week_day = ChoiceField(choices=(('monday', '周一'), ('tuesday', '周二'), ('wednesday', '周三'), ('thursday', '周四'), ('friday', '周五'), ('saturday', '周六'), ('sundayabel='星期n', required=True)
        discount_factor = FloatField(label='优惠折扣系数', max_value=1.0, min_value=0.0, required=True)
        class Meta:
            validators = [<UniqueTogetherValidator(queryset=DiscountRule.objects.all(), fields=('week_day', 'discount_factor', 'st_time', 'end_time'))>]
    
  • 相关阅读:
    MYSQL数据库实验(存储过程与触发器)
    Markdown
    EXT文件系统
    Arch在VirtualBox虚拟机中挂载U盘
    U盘启动没有引导项
    安装ArchLinux的两篇博文
    Arch Linux上安装Win10
    Gentoo系统安装痕迹化记录
    物联网操作系统安全研究综述
    2013.06_多线程_多核多线程技术综述_眭俊华
  • 原文地址:https://www.cnblogs.com/li-gao-wang/p/15356215.html
Copyright © 2020-2023  润新知