An example of how django forms implement drop down boxes

  • 2020-09-28 09:00:28
  • OfStack

Method 1:


queue = forms.ModelChoiceField(label=u' The queue ',queryset=Queue.objects.all())

Method 2:


 class ServerForm(forms.Form):
 queue = forms.ChoiceField(label=u' The queue ')
 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())

Note: In the Queue model with the function of succunicode__ (), return the fields you need to display with the drop-down menu


Related articles: