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‘)