脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - django表单实现下拉框的示例讲解

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

2021-02-26 00:24d_hyacinth Python

今天小编就为大家分享一篇django表单实现下拉框的示例讲解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

方法一:

?
1
queue = forms.ModelChoiceField(label=u'队列',queryset=Queue.objects.all())

方法二:

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

以上这篇django表单实现下拉框的示例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/d_hyacinth/article/details/54290300

延伸 · 阅读

精彩推荐