djangosnippets.org: Latest snippets posted by hotanihttps://djangosnippets.org/users/hotani/2007-04-28T13:37:29.021318-05:00hotaniCustom 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 redistributableName Capitalize Filter
2007-04-28T13:15:42.369170-05:00hotanihttps://djangosnippets.org/snippets/206/<p>This is to be used as a template filter. See <a href="http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-filters">django documentation</a> for adding custom filters.</p>
<p>Example of use:</p>
<p>name = "bart simpson"
<code>{{ name|cap }}</code> will convert 'name' to "Bart Simpson"</p>
<p>It works on space-separated names, as well as the following:</p>
<ul>
<li>converts "mcfly" to "McFly";</li>
<li>converts "o'neill" to "O'Neill"; …</li></ul>
Freely redistributable