Rendering a Django radio button

I have this form , with choices

subject_type = forms.ChoiceField(choices=Subject_type.objects.all(), widget=forms.RadioSelect)

but I want to render these choices with radio buttons in html, but I have troubles.

Upvotes: 1

Views: 168

Answers (1)

Vidya
Vidya

Reputation: 30310

You can still define your choices even though they are in a database:

subject_choices = dict([ (subject.id, subject.name) for subject in Subject_type.objects.all() ])

And then

subject_type = forms.ChoiceField(choices=subject_choices, widget=forms.RadioSelect)

Hope that helps.

Upvotes: 1

Related Questions