[Answered ]-Django query – how to get latest row during distinct

2👍

It looks as if you want the record with the largest id (among the records with the right value for von_location). That’s the first record retrieved when you sort them in descending order by the id column:

Rating.objects.filter(von_location=1).order_by('-id')[0]

Leave a comment