create a widget in init forms

[ permalink ] [ download ] [ 0 comments ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14
  class selectHomeForm(forms.Form):
    
    title = forms.CharField(max_length=50, label = 'Select homes:')  
    
    def __init__ (self, *args, **kwargs):
        super(selectHomeForm, self).__init__(*args, **kwargs)
        homes =  homeMap.objects.all()
        ourchoices = []
        for i in homes:
            value = (i.id, i.title)
            ourchoices.append(value)
            
        self.fields['title'].widget = forms.CheckboxSelectMultiple(choices = ourchoices)