Create empty queryset by default in django form fields

后端 未结 2 711
抹茶落季
抹茶落季 2021-01-30 08:09

I have this fields in form:

city = forms.ModelChoiceField(label=\"city\", queryset=MyCity.objects.all())
district = forms.ModelChoiceField(label=\"district\", qu         


        
2条回答
  •  再見小時候
    2021-01-30 08:25

    You can have an empty queryset by doing this:

    MyModel.objects.none()
    

    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

提交回复
热议问题