django - 我如何在 settings.py 文件中设置 default_currency= "INR" 因为它在项目中多次使用?
问题描述
我想将 MoneyField 详细信息保存在 setting.py 文件中,这样我就可以在每个使用 MoneyField 的地方使用它我想保存它..
MoneyField(max_digits=10, decimal_places=2, default_currency='INR', null=False, default=0.0)
如何将其保存在settings.py中
解决方案
Django uses a setting named DEFAULT_CURRENCY
to set the currency, the default is 'XYZ'
. Indeed, if we look at the source code [GitHub], we see:
from ..settings import CURRENCY_CHOICES, DECIMAL_PLACES, DEFAULT_CURRENCY
# …
class MoneyField(models.DecimalField):
# …
def __init__(
self,
# ...,
default_currency=DEFAULT_CURRENCY,
# …
):
# …
# …
You thus can set the DEFAULT_CURRENCY
in the settings.py
to:
# settings.py
# …
DEFAULT_CURRENCY = 'INR'
# …
and the omit the default_currency='INR'
parameters when you create MoneyField
s.
推荐阅读
- javascript - 使用 Vue.js 加载时,Swiper 无法正确显示图像
- automation - 如何以编程方式为基于库的应用程序配置 Azure AD SSO?
- azure - Azure Devops 从 Docker 内的 Azure Artifacts 安装 Python 包
- sql - 从表中选择不同的值并将它们放在字符串中
- appendchild - 函数中的问题:appendchild 不是函数
- tensorflow - TF2.1:SegNet 模型架构问题。度量计算的错误,保持不变并收敛到确定的值
- python - 为什么恢复保存的 DDPG 模型时的结果与保存时的结果有很大差异?
- c++ - boost.asio 传输文件 - 没有完全传输?- 内存映射性能?
- javascript - 如何持续检测 Pepper 面前是否有人?
- python - 使用 python 创建独立的 windows 应用程序,包括 excel 导入和不同的库