Yes, I use Form. Here's it's contents:
from django import forms
from .widgets import ChainedSelectWidget
from .models import Child
class SponsorForm(forms.Form):
child = forms.IntegerField()
class FilterForm(forms.Form):
gender = forms.ChoiceField(choices=[(x, x) for x in ('-----', 'MALE', 'FEMALE')], required=False)
age = forms.ChoiceField(choices=[(x, x) for x in range(1, 18)], required=False)
# orphaned = forms.BooleanField(initial=False,required=False)
# extreme_need = forms.BooleanField(initial=False,required=False)
handicapped = forms.ChoiceField(choices=[(x, x) for x in ('-------', 'Mental', 'Physcal')], required=False)
def __init__(self, *args, **kwargs):
super(FilterForm, self).__init__(*args, **kwargs)
if 0 == len(self.data):
self.fields['age'].queryset = Child.objects.none()
# assign a widget to second select field
self.fields['age'].widget = ChainedSelectWidget(
parent_name='gender', # the name of parent field
app_name='sponsorship', # the name of model's application
model_name='child', # the name of a model with the method
method_name='get_children', # the name of queryset method
)
It is for finding a child who may or may not have one of two types of handicaps.
-Eileen