django order by related field

前端 未结 2 459
说谎
说谎 2021-01-04 01:23

I want to sort a QuerySet of contacts by a related field. But I do not know how. I tried it like this, but it does not work.

foundContacts.order_by(\"classif         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-04 02:09

    as the documentation indicates, it should be used as in queries about related models

    https://docs.djangoproject.com/en/3.0/ref/models/querysets/#order-by

    foundContacts.order_by("classification__kam")
    

提交回复
热议问题