1
的fromfield方法形成場按照documentation:Django中,將參數傳遞給從定製模型字段
所有字典被直接傳遞給表單字段的__init __的kwargs()方法
def formfield(self, **kwargs):
# This is a fairly standard way to set up some defaults
# while letting the caller override them.
defaults = {'form_class': MyFormField}
defaults.update(kwargs)
return super(HandField, self).formfield(**defaults)
如果MyFormField是:
class GeopositionField(forms.MultiValueField):
def __init__(self, *args, **kwargs):
for name, value in kwargs.items(): # this doesn't print anything
print name
print value
self.widget = GeopositionWidget()
fields = (
forms.DecimalField(label=_('latitude')),
forms.DecimalField(label=_('longitude')),
)
super(GeopositionField, self).__init__(fields, required=False)
我怎麼會PA ss參數到formfield並獲取它init方法?