Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save markddavidoff/df3171e05b7dfaac2b524cecdfeda4ed to your computer and use it in GitHub Desktop.
Save markddavidoff/df3171e05b7dfaac2b524cecdfeda4ed to your computer and use it in GitHub Desktop.
Find All most recent Historical Models objects for a Model tracked by simple history
hists = HistoricalModel.objects.values('id').annotate(max_pk=Max('pk')).order_by()
most_recent_hist_model_for_model = dict(hists.values_list('id', 'max_pk'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment