1 2 3 4 5 6 7 8 9 10 11 12 | # dict indexed to model names
tables = {'str':'%s'}
for x in ModelOne, ModelTwo:
tables[x._meta.object_name] = x._meta.db_table
cursor = connection.cursor()
ex_str = """\
select field1, field2, sum(field3) from %(ModelOne)s where date between %(str)s and %(str)s
group by field1, field2
""" % tables
cursor.execute(ex_str, dates)
sumt = cursor.fetchall()
|
More like this
- SQL Function Decorator by proc 3 years, 5 months ago
- format output as table by bendavis78 2 years, 7 months ago
- fast table flush without raw SQL by dsblank 2 years, 1 month ago
- Locking tables by miohtama 3 years, 7 months ago
- Drop all tables in MySQL database by mpasternacki 2 years ago
Comments