python - Django模型设置字段默认为另一个字段
问题描述
我花了一些时间阅读其他问题,但我觉得我的问题有所不同,所以这里是:
class myModel(models.Model):
foo = models.DecimalField(decimal_places=2)
bar = models.DecimalField(decimal_places=2, default=foo)
我想bar
作为foo
默认值,但我得到一个
TypeError: conversion from DecimalField to Decimal is not supported
我应该怎么办?我应该按照其他帖子中的建议使用覆盖功能吗?
先感谢您!
解决方案
推荐阅读
- oracle - FOR variable_name IN (values)怎么办?(使用枚举值而不是范围)
- networking - Kubectl:通过企业 SSL 感知代理访问 AKS (Kubernetes) 公共 API 端点
- android-studio - Android Studio如何在颤动中删除构建方法中的行
- matlab - 有没有办法绘制一个带有方程(来自 ODE 系统)的函数 f?
- r - R:使用 MatchIt 进行倾向得分匹配。如何使用replace = TRUE找到匹配观察的数量?
- java - 使用 ExecutorService 在具有通过循环传递的不同参数的类中同时执行方法的问题
- python-3.x - 如何将父ID分配给具有多个级别的xml中的子代
- android - 如何使用codeigniter将android活动中的数据发布到mysql数据库中?
- asp.net-core - 如何将 RFC 8288 HTTP 链接头添加到响应中
- python - 是否可以搜索特定版本的软件包何时发布?