I have this fields in form:
city = forms.ModelChoiceField(label="city", queryset=MyCity.objects.all())
district = forms.ModelChoiceField(label="district", queryset=MyDistrict.objects.all())
area = forms.ModelChoiceField(label="area", queryset=MyArea.objects.all())
district comes from click on city and area comes from click on area. With queryset=MyDistrict.objects.all()
and queryset=MyArea.objects.all()
form will be very heavy. How can I make querysets empty by default?
Best Solution
You can have an empty queryset by doing this:
Although i don't know how are you going to use that form, you can put that as your field's queryset in order to get what you need...
You can find more information here