First, why aren't you using Django ORM for this?
MyClass.objects.filter( aField__contains=var1, secondField__exact=var2 )
Secondly, make sure you get the expected SQL.
stmt= "select... afield like '%%%s%%' and secondfield = '%s'..." % ( var1, var2 ) print stmt cursor.execute( stmt )
Third, your method has a security hole called SQL Injection Attack. You really should not do SQL like this.
If you absolutely must do something outside of Django ORM, you need to use the bind variables in your request, not the replacement string. See http://docs.djangoproject.com/en/dev/topics/db/sql/#performing-raw-sql-queries .
source share