标签:val def self ali choices form 构造 values initial
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‘)
标签:val def self ali choices form 构造 values initial
原文地址:https://www.cnblogs.com/jiefangzhe/p/10802237.html