how to create an empty queryset and to add objects manually in django [closed]

You can do it in one of the following ways:

from itertools import chain
#compute the list dynamically here:
my_obj_list = list(obj1, obj2, ...)
#and then 
none_qs = MyModel.objects.none()
qs = list(chain(none_qs, my_obj_list))

You could also do:

none_qs = MyModel.objects.none()
qs = none_qs | sub_qs_1 | sub_qs_2

However, This would not work for sliced querysets

Leave a Comment