Reputation: 1411
Consider I have a model named History and it has data like this.
name comment date
----------------------------------
Jake some comment 2017-06-20
John some comment 2017-08-20
Jake some comment 2017-06-21
Albert some comment 2017-06-21
and from the above sample data, I want to get distinct data based on the datetime field. For example, the result should look like below from the above sample data.
name comment date
----------------------------------
John some comment 2017-08-20
Jake some comment 2017-06-21
Albert some comment 2017-06-21
How can I write an ORM for this? can anyone please help me!
Upvotes: 0
Views: 24
Reputation: 3588
I think you should try this:
History.objects.order_by('name', '-date').distinct('name')
Upvotes: 2