开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜