Django之ModelForm:can't assign must be a instance

川长思鸟来 2022-05-08 06:16 454阅读 0赞
  1. class DeployApplyForm(ModelForm):
  2. //project = forms.ChoiceField(choices=Project.objects.filter(prj_mgr='').value_list('id','name'))
  3. //使用上述代码会报can't assign must be a instance,所以要使用下行代码
  4. project = forms.ModelChoiceField(queryset=Project.objects.filter(prj_mgr=''))
  5. bgn_time = forms.DateTimeField(initial=datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S"), label=u'开始',
  6. input_formats=['%Y-%m-%dT%H:%M:%S'], widget=forms.DateTimeInput(
  7. attrs={'type': 'datetime-local', 'emptyTips': u'请选择时间', 'step': '1'}))
  8. end_time = forms.DateTimeField(initial=datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S"), label=u'结束',
  9. input_formats=['%Y-%m-%dT%H:%M:%S'], widget=forms.DateTimeInput(
  10. attrs={'type': 'datetime-local', 'emptyTips': u'请选择时间', 'step': '1'}))
  11. class Meta:
  12. model = DeployApply
  13. fields = '__all__'

参考文章:
https://stackoverflow.com/questions/26580192/cannot-assign-must-be-a-instance-django

发表评论

表情:
评论列表 (有 0 条评论,454人围观)

还没有评论,来说两句吧...

相关阅读