Skip to content

Instantly share code, notes, and snippets.

@jawnb
Last active August 29, 2015 14:03
Show Gist options
  • Save jawnb/cd7a899cac5300c01709 to your computer and use it in GitHub Desktop.
Save jawnb/cd7a899cac5300c01709 to your computer and use it in GitHub Desktop.
django orm is terrible
In [9]: print User.objects.extra(select={'foo': 'bar'}).query
SELECT (bar) AS "foo", "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user"
In [10]: print User.objects.extra(select={'foo': 'bar'}).annotate().query
SELECT (bar) AS "foo", "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" GROUP BY "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined", (bar)
There is no way to not group by your extra field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment