Custom SQL Function; Outputs Template-Friendly Content

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# custom query function:
def csql(self,query,qkeys):
    from django.db import connection
    cursor = connection.cursor()
    cursor.execute(query)
    rows = cursor.fetchall()
    
    # build dict for template:
    fdicts = []
    for row in rows:
        i = 0
        cur_row = {}
        for key in qkeys:
            cur_row[key] = row[i]
            i = i+1
        fdicts.append(cur_row)
    return fdicts

More like this

  1. View decorator to automate templates. by jafo 4 years, 2 months ago
  2. Last.fm Charts by sedden 5 years, 9 months ago
  3. Output sql_queries in Firebug console when in debug mode by wojas 4 years, 1 month ago
  4. Improved generic foreign key manager 2 by Nomalz 4 years, 5 months ago
  5. Django Dictionary Model by Morgul 2 years, 10 months ago

Comments

(Forgotten your password?)