I have a queryset(which is filtered actually) as below
posts = [, , , ,
The previous answers are correct if each list item already exists in the database, but sometimes this is not the case. In this case you can create a queryset stub based on the list and implement queryset-methods and queryset-properties as needed.
class ListAsQuerySet(list):
def __init__(self, *args, model, **kwargs):
self.model = model
super().__init__(*args, **kwargs)
def filter(self, *args, **kwargs):
return self # filter ignoring, but you can impl custom filter
def order_by(self, *args, **kwargs):
return self
qs = ListAsQuerySet(custom_list, model=Post)