Django query with distinct and order_by

前端 未结 1 1626
醉酒成梦
醉酒成梦 2021-02-19 01:28

I have two models

class Employer(models.Model):
     name = models.CharField(max_length=300, blank=False)
     id = models.IntegerField()
     status = models.In         


        
1条回答
  •  再見小時候
    2021-02-19 02:02

    You can place on the Employer class its latest JobTitle activation date, and then order by this field without using relations.[1] The tradeoff here is a bit of data duplication, and the necessity to update employer's latest job title activation date manually when corresponding JobTitle instance changes.

    Also, check this post for another solution which uses annotate().

    Related questions:

    [1] Queryset API distinct() does not work?

    0 讨论(0)
提交回复
热议问题