from django.db.models import Max, F
car_prices = CarPrice.objects.filter(car__in=cars) \
.annotate(latest=Max('car__carprice_set__start_date')) \
.filter(start_date=F('latest'))
This will annotate each CarPrice
object with the latest start_date
for all prices related to the CarPrice
's car. Filtering on start_date=F('latest')
will return only the latest object for each Car
.