Sorting. Django
Suppose i want to sort my entries in queryset by sum (or some formula) of two or more field.
for example:
sorted_artikles=Article.all().sort_by('sum_of_rating+user_vetes+user_readed')
example model:
Class Article(开发者_如何学JAVAmodels.Model):
text=CharField()
author=ForeinKey()
user_voted=IntegerField()
rating=IntegerField()
user_readed=IntegerField()
Should i subclass method order_by() ?
No. You should use the select
and order_by
arguments of the QuerySet.extra()
method.
精彩评论