I have this class in django 1.4:
class ProgramForm(forms.ModelForm):
...other fields...
program_interests = forms.ModelMultipleChoiceField(
widget=forms.Select(),
queryset= Programs.objects.filter(is_active=True),
required=True,
label="Program Interest",
)
And this works fine; the template looks like this:
{% get_fieldset other_fields,program_interests as the_fields from programform %}
{% for field in the_fields %}
<li id="li_{{field.html_name}}">
<label for="id_{{ field.html_name }}">{{ field.label }}</label>
{{ field }}
</li>
{% endfor %}
My 'Programs' model has a field for type
of program. What I want to do is populate program_interests
' ModelMultipleChoiceField
and order them first by type
of program and then alpha. Each type
of program will have a label in the drop down (a disabled option). So, what I want to do is something like this:
qs1 = Programs.objects.filter(is_active=True, type=1),
qs2 = Programs.objects.filter(is_active=True, type=2),
qs3 = Programs.objects.filter(is_active=True, type=3),
queryset = qs1 | qs2 | qs3,
But this doesn't work. Any idea if I'm going about this the right way?
EDIT: what I've tried
q1 = Q(is_active=True,type=1)
q2 = Q(is_active=True,type=2)
q3 = Q(is_active=True,type=3)
program_interests = forms.ModelMultipleChoiceField(
widget=forms.Select(),
queryset= Programs.objects.filter(q1 | q2 | q3).order_by('type'),
required=True,
label="Program Interest",
)
This could work if I can append a disabled input inbetween the q1
and q2
to use as a label. Anyone know how I would do that?