Is it possible to set a form's ForeignKey field's queryset so that it will take separate queryset's and output them in <optgroup>
's?
Here is what I have:
views.py
form = TemplateFormBasic(initial={'template': digest.template.id})
form.fields['template'].queryset = Template.objects.filter(Q(default=1) | Q(user=request.user)).order_by('name')
In my Template model, I have default Templates and User-created templates. I want them to be visibly separated in the <select>
box eg.
<select>
<optgroup label="Default Templates">
<option>Default 1</option>
<option>Default 2</option>
</optgroup>
<optgroup label="User Templates">
<option>User Template 1</option>
<option>User Template 2</option>
</optgroup>
</select>
Can this be done?