how to sort by a computed value in django

前端 未结 3 1474
深忆病人
深忆病人 2020-12-19 07:53

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

3条回答
  •  星月不相逢
    2020-12-19 08:36

    Since your calculation code exists only within Python, you have to perform the sorting in Python as well:

    sorted (Profile.objects.all (), key = lambda p: p.reputation)
    

提交回复
热议问题