I have a queryset(which is filtered actually) as below
posts = [, , , ,
Here's a simple util that you can run to produce a QS from a list:
def list_to_queryset(model, data):
from django.db.models.base import ModelBase
if not isinstance(model, ModelBase):
raise ValueError(
"%s must be Model" % model
)
if not isinstance(data, list):
raise ValueError(
"%s must be List Object" % data
)
pk_list = [obj.pk for obj in data]
return model.objects.filter(pk__in=pk_list)