Django custom order_by

前端 未结 3 2025
余生分开走
余生分开走 2020-12-09 22:37

I\'ve got a model eg. Car with a foreign key eg. Owner, which may or may not be blank. The Car has a creation_date.

I would like to order these cars by date, but if

3条回答
  •  一向
    一向 (楼主)
    2020-12-09 23:13

    You could write a method that returns the appropriate date (if car has owner return birthday else return creation_date) and then order your model based on this method.

提交回复
热议问题