title: Serving .json file to download
body: <p>I am trying to serve a .json file through this function. The problem is that every time I make the request the browser displays the content instead of downloading the file.</p>
  
  <p>I think it could be due to the fact that I am using <code>.read()</code> as a parameter for the HttpResponse object constructor. However, if I use only the file object, I get the following exception:</p>
  
  <pre><code>TypeError: cannot serialize '_io.BufferedRandom' object
  </code></pre>
  
  <p>Code</p>
  
  <pre><code>try:
      invoices = models.Invoice.objects.filter(pk__in=document_ids).order_by(*ordering)
      pcustomers = models.CustomerProxy.objects.all()
      mixed_query = list(invoices) + list(pcustomers)
  
      file = tempfile.NamedTemporaryFile(suffix='.json')
      file.write(serializers.serialize('json', mixed_query).encode())
      file.seek(0)
  
      response = HttpResponse(file.read(), content_type='application/json')
      response['Content-Disposition'] = 'attachment; filename=%s' % file.name
      response['Content-Length'] = os.path.getsize(file.name)
  
  except Exception:
      raise
  
  return response
  </code></pre>