I am using distinct to get the distinct latest values but it is giving me an error:
DISTINCT ON fields is not supported by this database backend
views.py
class ReportView(LoginRequiredMixin, generic.TemplateView):
template_name = 'admin/clock/report.html'
def get_context_data(self, **kwargs):
context = super(ReportView, self).get_context_data(**kwargs)
context['reports'] = TimesheetEntry.objects.filter(
timesheet_jobs__job_company = self.request.user.userprofile.user_company,
).distinct('timesheet_users')
return context
Basically I want to query on TimesheetEntry
model where there will be lot of entries of user
which is a foreign key in User
in-built model.
So I want to query with distinct user so that latest entry of the user will be displayed. It is very important for me to get the latest entry of user.
models.py
class TimesheetEntry(models.Model):
timesheet_users = models.ForeignKey(User, on_delete=models.CASCADE,related_name='timesheet_users')
timesheet_jobs = models.ForeignKey(Jobs, on_delete=models.CASCADE,related_name='timesheet_jobs')
timesheet_clock_in_date = models.DateField()
timesheet_clock_in_time = models.TimeField()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…