title: Django: raw SQL queries with a dynamic number of variables
body: <p>Is it possible to construct raw SQL queries in Django so that they accept a dynamic number of arguments? So for example say that I have the following url structure in my app:</p>
  
  <pre><code>/books/category/history/
  /books/category/history/1800s/
  </code></pre>
  
  <p>For the first query, I'm looking for all books with the keyword 'history', and for the second, I'm looking for all books with the keyword 'history' AND the keyword '1800s'.</p>
  
  <p>I currently have two separate queries for each of these:</p>
  
  <pre><code>keyword1 = 'history'
  SELECT appname_book.name AS name FROM appname_book WHERE keyword=%s,[keyword1]
  
  keyword1 = 'history'
  keyword2 = '1800s'
  SELECT appname_book.name AS name FROM appname_book WHERE keyword=%s AND keyword=%s,[keyword1, keyword2]
  </code></pre>
  
  <p>Anyone know of a cleaner and more efficient way to do this?</p>
  
  <p>I'm using Django 1.3 and MySQL.</p>
  
  <p>Thanks.</p>