Tuesday, 14 May 2013

Django - Drop Down List Data Refresh/Reload

forms.py
INITIAL_CHOICE = ('', '---------')
class ProfileForm(forms.Form):
    profile_id = forms.ChoiceField(label=_('Profile'), choices=[INITIAL_CHOICE])
 
    def __init__(self, *args, **kwargs):
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields["profile_id"].choices = [INITIAL_CHOICE]+[(obj.id, "%s [%s]" % (obj.name, obj.identity,)) for obj in Profile.objects.all()]
 

No comments :

Post a Comment