I have a model consists of order field , I want to fetch that row who have max value for
Class MyModel(models.Model): user = models.ForeignKey(User) order = models.IntegerField()
Now let say I want to fetch records for user 1 , for this user total no of rows exist in table are
10 but I want only that row who have max order value.
Also If I wanted to fetch records for two users then same condition must be applied. For this filter query must return one row for every user with max value for
right I am using annotate but it returns all rows
rows = MyModel.objects.annotate(max_seq=Max('order')).filter(user = 1)
so when I loop over this rows it print all 10 rows , but it must return only one row with col max order value