Hey I want to sort objects based on a computed value in django... how do I do it?
Here is an example User profile model based on stack overflow that explains my pred
As of Django-1.8, it is possible to sort a QuerySet using query expressions as long as the computed value can be rendered in SQL. You can also use annotations to the model as the order_by term.
from django.db.models import F
Profile.objects.annotate(reputation=(F('') + ...)).order_by("-reputation")
Basic operations like +, -, *, / and ** can be used with F(). In addition there are several other functions such as Count, Avg, Max, ...
Links:
See also this SO Q&A: Order a QuerySet by aggregate field value