A QuerySet by aggregate field value

后端 未结 3 451
梦如初夏
梦如初夏 2020-11-27 04:02

Let\'s say I have the following model:

class Contest:
    title = models.CharField( max_length = 200 )
    description = models.TextField()

class Image:
            


        
3条回答
  •  时光取名叫无心
    2020-11-27 04:17

    The db-level order_by cannot sort queryset by model's python method.

    The solution is to introduce score field to Image model and recalculate it on every Vote update. Some sort of denormalization. When you will can to sort by it.

提交回复
热议问题