Django: A simple order and distinct query

0 Comments

A common query in SQL would be:

1.SELECT DISTINCT type FROM Item ORDER BY type;

In Django however, it's a little tricker since we've got the ORM.

1.Items.objects.order_by('type').values_list('type', flat = True).distinct()

Unusual? Yes. Impossible? No.

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog