Hello. I have this form:
class LocalityForm(forms.Form): region = forms.ModelChoiceField(queryset=Region.objects.all(), required=False, empty_label=") locality = forms.ModelChoiceField(queryset=Locality.objects.none(), required=False, empty_label=") #in order to be able to select the city depending on #region transferred to the POST, and back in already entered data added to the form so def __init__(self, data = None, *args, **kwargs): super(forms.Form, self).__init__(*args, **kwargs) if data: if data.get('region'): self.reg = data['region'] self.fields['region'].initial = self.reg self.fields['locality'].queryset = Locality.objects.filter(region=self.reg).order_by('name') if data.get('locality'): self.loc = data['locality'] self.fields['locality'].initial = self.loc
called quite simply form = LocalityForm(request.POST)
But then disappears test the form, i.e. the form is in any case not valid, probably due to the intercept POST data argument data.
To pass through named arguments is not desirable because the press is becoming quite idiotic
form = LocalityForm(request.POST, region = request.POST['region'], locality = request.POST['locality'])
Although if there is no other solution that apparently will have to settle for what we have.