Two options I can think of quickly: 1. in the __init__ of the form, see if a value has been passed in for the League and School and only if there is none, create the queryset as described. 2. Do not use a model form to create the initial form, just use a simple template and the javascript you have to accept the entries, and then upon submit pass it to the form without the default none()'s for validation.
A third option is (using javascript) ask the user what school they go to/went to/would like to go to or whatever and then after verification that it is a valid choice, fill out the League and State for them. The way you have described sounds a bit overly complex from a usability point of view. But I obviously do not understand your detailed requirements. HTH, -richard On 5/29/08, Adi <[EMAIL PROTECTED]> wrote: > > > I have a form that has three fields > 1. State > 2. League > 3. School > > The model for League has a foreign Key into the model for State > The model for School has a foreign Key into the model for League > > The user is supposed to chose the state first (which is USStateField), > then the list of League is supposed to get populated. The use is > supposed to choose the League which is supposed to populate the > choices of School for the user to select. The user finally is supposed > to select school. > > The three fields are as follows: > state = USStateField(required=True,widget=USStateSelect) > league = forms.ModelChoiceField(queryset=League.objects.none(), > empty_label="Please select state first", cache_choices=True, > required=False, label="League") > school = forms.ModelChoiceField(queryset=School.objects.none(), > empty_label="Please select league first", cache_choices=True, > required=False, label="School") > > I have the JS implemented that populates the fields dynamically based > on user selection and that is working fine. > > My questions are as follows: > 1. If I select the three fields, and submit the form, I get back an > error saying "Select a valid choice. That choice is not one of the > available choices." for both the League and School fields. So, > basically the values are not sticking to the form. I guess this is > because my queryset specifies League.objects.none(). How do I make the > values bind to the fields without having to resort to changing the > queryset to League.objects.all(). I don't want to do this cos the > League data is huge. > > 2. Since the fields don't bind to the values, when the form get > redisplayed, the values are not redisplayed. > > I am struggling with the ModelChoiceField in general as well. > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---