日常记Bug

前记:后端写代码应该对数据的交互更加掌握,不要被编码、数据模型细节坑住


Unicode编码、Django数据迁移偶尔产生的不稳定

处理细项工资记录模型:

class TeachRoll(models.Model):  # 教学细项工资管理(教学加班,德育补助,安全补助等等)
    staff = models.ForeignKey(basic_models.Staff)
    item = models.ForeignKey(basic_models.TeachItem)  # 注意这个是teachitem
    teach_time = models.FloatField(default='0')  # 教学课时支持浮点数
    the_price = models.FloatField(default='0')  # 当时这条课时记录的课时单价
    money = models.FloatField()  # 教学细项工资记录的价格
    give_time = models.CharField(max_length=64)  # '年月'
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now_add=True)

    class Meta:
        # unique_together = ('staff', 'teach_time', 'give_time')  # 同员工同条目同年月工资记录不可重复
        unique_together = ('staff', 'item', 'give_time')  # 同员工同条目同年月工资记录不可重复

模型建立时因为没注意,把unique的三个属性写错了,导致视图函数中create记录时报错,还以为是编码问题,找了许久。'7-0-2019'???。对数据库迁移和数据交互还是要更加细心和深入理解。

猜你喜欢

转载自www.cnblogs.com/bqwzx/p/10735000.html