Created
October 20, 2017 13:27
-
-
Save ilosamart/8e8b4429d8e8c9d5a95a0bf9f832a3ec to your computer and use it in GitHub Desktop.
django distinct baka
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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