django表单实现下拉框的示例讲解
时间:2021-07-15 09:30:51|栏目:Python代码|点击: 次
方法一:
queue = forms.ModelChoiceField(label=u'队列',queryset=Queue.objects.all())
方法二:
class ServerForm(forms.Form): queue = forms.ChoiceField(label=u'队列') def __init__(self,*args,**kwargs): super(ServerForm,self).__init__(*args,**kwargs) self.fields['queue'].choices=((x.que,x.disr) for x in Queue.objects.all())
注意:在Queue模型的__unicode__()函数中返回你下拉菜单需要显示的字段
栏 目:Python代码
下一篇:解决Python出现_warn_unsafe_extraction问题的方法
本文标题:django表单实现下拉框的示例讲解
本文地址:http://www.codeinn.net/misctech/157546.html






