1. 程式人生 > >form組件 初始化

form組件 初始化

ber () rgs form BE value self. 數據庫查詢 cap

 1 class MyForm(Form):
 2  
 3     user = fields.ChoiceField(
 4         # choices=((1, ‘上海‘), (2, ‘北京‘),),
 5         initial=2,
 6         widget=widgets.Select
 7     )
 8  
 9     def __init__(self, *args, **kwargs):
10         super(MyForm,self).__init__(*args, **kwargs)  #每次生成初始化self.filed,區數據庫查詢
11 # self.fields[‘user‘].widget.choices = ((1, ‘上海‘), (2, ‘北京‘),) 12 # 13 self.fields[user].widget.choices = models.Classes.objects.all().value_list(id,caption)

form組件 初始化