There is a Django view that loads Member
objects from the database with a certain filter.
Now I need to change this logic to present a specific Member
first, and let the rest follow in their natural order.
The most straightforward way is to execute the query right away, get a list, remove and insert the item at the beginning. However I am most curious if there is still any way to make use of QuerySet
's lazy nature.
In C#, I would write:
IEnumerable<Member> members = db.Members; // db.Members is lazy
members = Enumerable.Union( // construct a lazy sequence that traverses its arguments
new [] { specificMember },
members.Where(m => m != specificMember)
);
As a loop would go through members
, it would first get specificMember
and then use whatever lazy loading logic original db.Members
used.
Is there a way to do the same in Django and Python?