You need to call the __init__
to load the data in form dynamically. For example:
class YourForm(forms.Form):
queue = forms.ChoiceField(label=u'queue')
def __init__(self, *args, **kwargs):
super(YourForm, self).__init__(*args, **kwargs)
self.fields['queue'].choices = ((x.que,x.disr) for x in Queue.objects.all()))
Reason for doing it is that, if you call __init__
in your form, it initializes an instance of a class and updates the choice list with latest data from database. For detail understanding, check here:Why do we use __init__ in python classes?