[Fixed]-DISTINCT ON fields is not supported by this database backend

31👍

distinct('field_name') is not supported in MySQL. It only support distinct(). distinct('field_name') will only work on PostgresSQL. For more details, please check the documentation.

Examples (those after the first will only work on PostgreSQL):(Copy Pasted from Documentation:)

>>> Author.objects.distinct() 
   [...]

>>> Entry.objects.order_by('pub_date').distinct('pub_date')
   [...]

>>> Entry.objects.order_by('blog').distinct('blog')
   [...]

>>> Entry.objects.order_by('author', 'pub_date').distinct('author', 'pub_date')
   [...]

>>> Entry.objects.order_by('blog__name', 'mod_date').distinct('blog__name', 'mod_date')
   [...]

>>> Entry.objects.order_by('author', 'pub_date').distinct('author')
   [...]
👤ruddra

-1👍

May you should this one

>>> queryset = TimesheetEntry.objects.distinct()
>>> context['reports'] = queryset .filter(timesheet_jobs__job_company = self.request.user.userprofile.user_company, )

Leave a comment