Skip to content

Instantly share code, notes, and snippets.

@ilosamart
Created October 20, 2017 13:27
Show Gist options
  • Save ilosamart/8e8b4429d8e8c9d5a95a0bf9f832a3ec to your computer and use it in GitHub Desktop.
Save ilosamart/8e8b4429d8e8c9d5a95a0bf9f832a3ec to your computer and use it in GitHub Desktop.
django distinct baka
# based in https://stackoverflow.com/a/43550457
for produto in Produto.objects.filter(id__in=[produto['x'] for produto in Produto.objects.values('nome').distinct().annotate(x=Max('id'))]):
print("%d %s %d" % (produto.id, produto.nome, produto.valor))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment