Django: A simple order and distinct query

A common query in SQL would be:

SELECT DISTINCT type FROM Item ORDER BY type;

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

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