【发布时间】:2022-01-14 01:46:55
【问题描述】:
如何在 django 字段中为货币和货币代码添加小部件? 我想在该字段中添加类“表单控件”。
templates.html
<div class="col-sm-4">
<label for="jumlahUsulanDana">Jumlah Usulan Dana</label>
{{form.jumlah_dana_usulan}}
</div>
forms.py
class Meta:
model = UserUsulan
exclude = ['status_usulan' ,'jumlah_dana_disetujui',
'keterangan_operator', 'com_reviewer_1', 'com_reviewer_2' ]
widgets = {'jumlah_dana_usulan' : forms.TextInput({'class' :
'form-control', 'id' : 'jumlahUsulanDana', 'placeholder'
: 'Jumlah Usulan Dana'}),
}
编辑
如果在 forms.py 中使用了 attrs,有什么想法吗?
models.py
from djmoney.models.fields import MoneyField
class UserUsulan(models.Model):
...
jumlah_dana_usulan = MoneyField(max_digits=14, decimal_places=2, default_currency='IDR')
...
【问题讨论】:
-
你能在这里添加你的模型吗?
-
也分享你的设置
CURRENCY_CHOICES变量。