djangosnippets.org: Latest snippets tagged with 'custom-sql'https://djangosnippets.org/tags/custom-sql/2011-01-06T15:17:34.687270-06:00post_migrate handler to load initial SQL after migrating with south
2011-01-06T15:17:34.687270-06:00stingydronehttps://djangosnippets.org/snippets/2311/<p>I found that South doesn't execute initial sql file after a migration, like what Django can do after syncdb. So here's the workaround by using post_migrate signal.
</p>
<p>Usage:
Put your SQL files the same way as you would if you were to use Django to load your initial SQL file …</p>
Freely redistributableCustom SQL Function; Outputs Template-Friendly Content
2007-04-28T13:37:29.021318-05:00hotanihttps://djangosnippets.org/snippets/207/<p>This will return a template-friendly list of dictionaries when using custom SQL. The dictionary can be accessed just as a normal model/queryset.</p>
<p>Example of use (in view):</p>
<pre><code>qkeys = ['artist','album']
query = """
SELECT "artist","album" FROM "music"
"""
new_list = csql(request,query,qkeys)
</code></pre>
<p>(in template)</p>
<pre><code>{% for row in new_list %}
{{ …</code></pre>
Freely redistributable