class DeployApplyForm(ModelForm):
//project = forms.ChoiceField(choices=Project.objects.filter(prj_mgr='').value_list('id','name'))
//使用上述代码会报can't assign must be a instance,所以要使用下行代码
project = forms.ModelChoiceField(queryset=Project.objects.filter(prj_mgr=''))
bgn_time = forms.DateTimeField(initial=datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S"), label=u'开始',
input_formats=['%Y-%m-%dT%H:%M:%S'], widget=forms.DateTimeInput(
attrs={'type': 'datetime-local', 'emptyTips': u'请选择时间', 'step': '1'}))
end_time = forms.DateTimeField(initial=datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S"), label=u'结束',
input_formats=['%Y-%m-%dT%H:%M:%S'], widget=forms.DateTimeInput(
attrs={'type': 'datetime-local', 'emptyTips': u'请选择时间', 'step': '1'}))
class Meta:
model = DeployApply
fields = '__all__'
参考文章:
https://stackoverflow.com/questions/26580192/cannot-assign-must-be-a-instance-django