Skip to content

Tag: python

Aggregating save()s in Django?

I’m using Django with an sqlite backend, and write performance is a problem. I may graduate to a “proper” db at some stage, but for the moment I’m stuck with sqlite. I think that my write performance problems are probably related to the fact that I’m creating a large number of ro…

How to use variables in SQL statement in Python?

I have the following Python code: where var1 is an integer, var2 and var3 are strings. How can I write the variable names without Python including them as part of the query text? Answer Note that the parameters are passed as a tuple. The database API does proper escaping and quoting of variables. Be careful n…

How to use “AND” in a Django filter?

How do I create an “AND” filter to retrieve objects in Django? e.g I would like to retrieve a row which has a combination of two words in a single field. For example the following SQL query does exactly that when I run it on mysql database: How do you accomplish this in Django using filters? Answe…