title: Reports With Django
body: <p>I'm trying to create a pretty advanced query within django and im having problems doing so, i can use the basic:</p>
  
  <pre><code>for obj in Invoice.objects.filter():
  </code></pre>
  
  <p>but if i try and move this into raw PostgreSQL query i get an error telling me that the relation does not exist am i doing something wrong, i am following the <a href="https://docs.djangoproject.com/en/1.10/topics/db/sql/" rel="nofollow">Preforming raw SQL</a> on the django documents but i keep getting same error</p>
  
  <p>full code: </p>
  
  <pre><code>def csv_report(request):
  response = HttpResponse(content_type='text/csv')
  response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
  
  writer = csv.writer(response, csv.excel)
  response.write(u'\ufeff'.encode('utf8'))
  writer.writerow([
      smart_str(u"ID"),
      smart_str(u"value"),
      smart_str(u"workitem content type"),
      smart_str(u"created date"),
      smart_str(u"workitem.id"),
      smart_str(u"workitem"),
      smart_str(u"workitem_content_type"),
  ])
  for obj in Invoice.objects.raw('SELECT * from twm_Invoice'):
      writer.writerow([
          smart_str(obj.pk),
          smart_str(obj.value),
          smart_str(obj.workitem_content_type),
          smart_str(obj.created_date),
          smart_str(obj.workitem_id),
          smart_str(obj.workitem),
          smart_str(obj.workitem_content_type),
      ])
  return response
  </code></pre>
  
  <p>i have tried to use the app now within front of the model name and without none of them seem to work.</p>
  
  <p>Thanks J</p>