我想设置字段以输入浓度及其单位。
我的模型中有:
class Cbc(models.Model):
...
hgb = models.PositiveSmallIntegerField()
以我的形式:
class CbcForm(forms.ModelForm):
...
class Meta:
field_classes = {
'hgb' : ConcentrationField,
}
...
23 class ConcentrationField(forms.MultiValueField):
24 def __init__(self, **kwargs):
25 _widget = WidgetConcentration
26 fields = (
27 forms.IntegerField,
28 forms.ChoiceField(choices=(('g/L', 'g/L'), ('g/dL', 'g/dL')), initial='g/L'),
29 )
30 super().__init__(fields=fields, widget = _widget, **kwargs)
31
32 def compress(self, values):
33 if values[1] == 'g/dL':
34 return values[0] * 10
35 return values[0]
但是我有一个错误:
TypeError: __init__() got an unexpected keyword argument 'min_value'
有人知道如何处理吗?