'I don’t understand how to write correct query to database by Django orm
I have two models:
Class Page(models.Model):
Id
Class LinkedPage(models.Model):
page = models.ForeignKey(Page)
created_year = models.IntegerField(…)
I want to get queryset of linkedPage that are group by page and have the highest created_year in the his group.
For example: There is page with 3 linked page created year that are 2011, 2005, 2019. There is the second page with 3 linked page created year that are 1960, 2017, 2005.
I want to get 2 records(instance with all fields) year that are 2019(from the first page) and 2017(from the second page).
I used a window function for this and it worked but I have to turn down them.
Thanks a lot
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
