Tôi có lĩnh vực này ở dạng:Tạo queryset trống theo mặc định trong các lĩnh vực hình thức 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())
huyện đến từ nhấp chuột vào thành phố và khu vực xuất phát từ nhấp chuột vào khu vực. Với hình thức queryset=MyDistrict.objects.all()
và queryset=MyArea.objects.all()
sẽ rất nặng. Làm thế nào tôi có thể làm cho queryset trống theo mặc định?
Cảm ơn trước
trong trường hợp sử dụng mà thay đổi queryset của bạn theo quan điểm của bạn dựa trên các thông số url. Sau đó, trong chế độ xem của bạn, bạn đặt đúng queryset như sau: edit_form.fields ["asset"]. Queryset = Asset.objects.filter (location_id = location_id) – radtek