How do I get the an object by name and highest timestamp

Viewed 66

I want to fetch the transaction belonging to external_id=1 and has the highest timestamp.

I have tried this

max_rating = Transaction.objects.aggregate(organisation_id_from_partner=organisation_id, highest_timestamp=Max('timestamp'))

But I get TypeError: QuerySet.aggregate() received non-expression(s): 1.

2 Answers

Inside aggregate, you can only write Aggregate function. Try this

max_rating = Transaction.objects.filter(organisation_id_from_partner=organisation_id).order_by('-timestamp').first()
Related