605👍
✅
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
3👍
@radtek’s comment should be an answer as it is useful in similar scenarios but with different approach than the accepted answer.
If your queryset changes with the url in your view.
I am extending the answer with example as I used:
def my_view(request):
...
form = YourForm(initial={'field1':value1, 'field2':value2})
form.fields['field3'].queryset = YourModel.objects.filter('foo'=bar)
- [Django]-Passing STATIC_URL to file javascript with django
- [Django]-How to check if a user is logged in (how to properly use user.is_authenticated)?
- [Django]-Mixin common fields between serializers in Django Rest Framework
Source:stackexchange.com