首页 > 解决方案 > 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

我应该怎么办?我应该按照其他帖子中的建议使用覆盖功能吗?

先感谢您!

标签: pythondjangodjango-models

解决方案


推荐阅读