2👍
✅
You can see the sql query to do the next:
queryset = Price.objects.all()
print queryset.query
If you know first sql query. You can do the subquery better.
Although, I do the next:
price_max = Price.objects.all().order_by('-created')[0]
queryset = Price.objects.filter(created=price_max)
Or the best:
https://docs.djangoproject.com/en/1.3/topics/db/aggregation/#generating-aggregates-over-a-queryset
from django.db.models import Max
price_max = Price.objects.aggregate((Max('created'))['created__max']
queryset = Price.objects.filter(created=price_max)
👤Goin
Source:stackexchange.com