Skip to content

Instantly share code, notes, and snippets.

@olivx
Created April 28, 2018 04:51
Show Gist options
  • Save olivx/0347b52821bcc47b0c344e7811f74d43 to your computer and use it in GitHub Desktop.
Save olivx/0347b52821bcc47b0c344e7811f74d43 to your computer and use it in GitHub Desktop.
''' lasts jobs for each candidate '''
_model = Candidate.objects.values('candidate').annotate(max_date=Max('apply_date')).order_by()
q_object = Q()
for last in _model:
q_object |= (Q(candidate=last['candidate']) & Q(apply_date=last['max_date']))
candidates = Candidate.objects.filter(q_object)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment