Django之ModelForm:can't assign must be a instance
阿新 • • 發佈:2018-12-14
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__'