95
我在这个表单字段:创建Django的表单字段默认为空查询集
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())
区来源于点击城市和地区来自点击区域。用queryset=MyDistrict.objects.all()
和queryset=MyArea.objects.all()
的形式会很重。我如何使查询集默认为空?提前
在这种基于URL参数在你看来你的查询集更改使用情况。然后在您的视图中设置正确的查询集,如下所示: edit_form.fields [“asset”]。queryset = Asset.objects.filter(location_id = location_id) – radtek