﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27496	Iterating over ModelChoiceField with RadioSelect widget duplicates query	Alex Fischer	nobody	"If you have a form with a ModelChoiceField using a RadioSelect widget and iterate over the individual radio inputs in your template (as demonstrated in the docs- https://docs.djangoproject.com/en/1.10/ref/forms/widgets/#radioselect), then the field's queryset will be evaluated for each option. Actually, the query seems to be executed 2n + 5 times, where n is the number of objects returned by the queryset.

To reproduce this, use the following code with any model and watch your database server logs.

{{{#!python
class BugTestForm(forms.Form):
    choice = forms.ModelChoiceField(queryset=MyModel.objects.all(), widget=forms.RadioSelect)

form = BugTestForm()
list(form['choice'])
}}}

The same issue occurs when using ModelMultipleChoiceField with a CheckboxSelectMultiple widget. 
 

"	Bug	closed	Forms	1.10	Normal	duplicate			Unreviewed	0	0	0	0	0	0
