Trying to get the last records I inserted in database based on DateTime and distinct column SocialMedia_ID but I get the following error DISTINCT ON fields is not supported by this database backend when it reaches to the below line:
accountsTwitter = StatsTwitter.objects.all().order_by('DateTime').distinct('SocialMedia_id')
I want to mention that below SQL query is working, and I need to convert it to django.
SELECT * FROM stats_Twitter WHERE DateTime IN (SELECT MAX(DateTime) FROM stats_Twitter GROUP BY SocialMedia_ID)
you can get the last records
if you want last n records then