How to sort a queryset of models in django by its function
I thought I knew how this worked but there is a bug which I can't seem to
figure out.
I have a query set where each of the models has a 'hotness()' method which
returns dynamically a hotness value.
Here is my code:
from item.models import Item
items = Item.objects.all()
items = sorted(items, key=lambda x: x.hotness, reverse=True)
# it does not work.
for i in items:
print i.hotness() # totally out of order, not even close
Any thoughts? Thanks.
No comments:
Post a Comment