网络编程
位置:首页>> 网络编程>> Python编程>> django表单实现下拉框的示例讲解

django表单实现下拉框的示例讲解

作者:d_hyacinth  发布时间:2022-03-24 09:18:25 

标签:django,下拉框,表单

方法一:


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__()函数中返回你下拉菜单需要显示的字段

来源:https://blog.csdn.net/d_hyacinth/article/details/54290300

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com