2010-10-12

foxfirefey: A guy looking ridiculous by doing a fashionable posing with a mouse, slinging the cord over his shoulders. (geek)
[personal profile] foxfirefey2010-10-12 01:47 pm

A simple distinct inner join in Django

Let's say I have ColorProperty and DWThemeColor (which is the through of a ManyToMany between DWTheme and ColorProperty). And I want to get all distinct ColorProperties that belong to DWThemes. This is how:

ColorProperty.objects.filter(dwthemecolor__isnull = False).distinct()

You don't even want to know how long it took me to figure this out, people.