Answer the question
In order to leave comments, you need to log in
Django: How to pass a POST to a form for processing?
Hello. I have this form:
class LocalityForm(forms.Form):<br>
region = forms.ModelChoiceField(queryset=Region.objects.all(), required=False, empty_label="")<br>
locality = forms.ModelChoiceField(queryset=Locality.objects.none(), required=False, empty_label="")<br><br>
#для того чтоб можно было выбрать населенный пункт в зависимости от<br>
#региона переданного в POST, а так же вернуть введенные уже данные дописал к форме так<br>
def __init__(self, data = None, *args, **kwargs):<br>
super(forms.Form, self).__init__(*args, **kwargs)<br>
if data:<br>
if data.get('region'):<br>
self.reg = data['region']<br>
self.fields['region'].initial = self.reg<br>
self.fields['locality'].queryset = Locality.objects.filter(region=self.reg).order_by('name')<br>
if data.get('locality'):<br>
self.loc = data['locality']<br>
self.fields['locality'].initial = self.loc<br>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question