djangosnippets.org: Latest snippets tagged with 'group-by'https://djangosnippets.org/tags/group-by/2007-05-14T23:46:04.035643-05:00Custom SQL via subquery
2007-05-14T23:46:04.035643-05:00drg006https://djangosnippets.org/snippets/236/<p>You can use custom SQL statements with the existing database API by creating a subquery specified via the <code>tables</code> parameter of <code>extra</code>. (This has only been tested with MySQL and may not work with all database back-ends.)</p>
Freely redistributableFetching top items
2007-02-25T00:43:02.372511-06:00ubernostrumhttps://djangosnippets.org/snippets/1/<p>This is a method from the custom manager for the Snippet model used on this site; the basic idea is to be able to ask for the top <code>n</code> "foo", where "foo" is something related to Snippet. For example, you can use <code>top_items('tag')</code> to get the top Tags ordered by …</p>
Freely redistributable