title: Improving performance of django DB query
body: <p>I'm using django/apache/sqlite3 and I have a django model that looks like this:</p>
  
  <pre><code>class Temp_entry(models.Model):
      dateTime = models.IntegerField() #datetime
      sensor = models.IntegerField()   # id of sensor
      temp = models.IntegerField()     # temp as temp in Kelvin * 100
  </code></pre>
  
  <p>I'm trying to get the last 300 Temp_entry items to place into a graph. I do that this way:</p>
  
  <pre><code>revOutsideTempHistory = Temp_entry.objects.filter(sensor=49).order_by('dateTime').reverse()[:300]
  </code></pre>
  
  <p>However, this query takes ~1 second.  Is there a way to improve this?  I've dug around and found that order_by is horrible inefficient, so I'm hoping that there is a viable alternative?</p>
  
  <p>An alternative I thought of, but can't figure out how to implement, would be to run the query every 20 minutes and keep it cached, that would be acceptable too, as the data can be slightly stale with no ill effects.</p>