63-05
必须先判断is_valid(),才能获取值.clean()
创建form对象时,从数据库取值初始化:
username = fields.CharField() user_type = fields.IntegerField( widget=widgets.Select(choices=[]) ) def __init__(self,*args, **kwargs): # 执行父类的构造方法 super(InitialForm,self).__init__(*args, **kwargs) self.fields['user_type'].widget.choices = models.UserType.objects.all().values_list('id','caption')