title: Django queryset to CSV, string field with quotes
body: <p>I have a feature where I translate a queryset to a CSV, and I have two string fields coming from a JSON, &quot;media&quot; and &quot;brand&quot;, but when I export it to CSV I got the media result with quotes and the brand field without quotes.</p>
  <p>I want to remove that quotes without having to parse the CSV because of performance.</p>
  <p>This is the process I do:</p>
  <pre><code>from django.db import connection
  from django.db.models.functions import Cast
  
  # Get queryset
  fields = {
      &quot;Media&quot;: Cast(&quot;event__media_name&quot;, output_field=CharField()),
      &quot;Brand&quot;: Cast(&quot;event__brand_name&quot;, output_field=CharField()),
  }
  queryset = (
     base_queryset.order_by(&quot;id&quot;)
     .annotate(**fields)
     .values(*fields.keys())
  )
  # Create CSV file
  filename = &quot;filename.csv&quot;
  path = f&quot;reports/{filename}&quot;
  folder = tempfile.mkdtemp()
  temp_path = os.path.join(folder, filename)
  # Copy values into CSV
  sql, params = queryset.query.sql_with_params()
  sql = f&quot;COPY ({sql}) TO STDOUT WITH (FORMAT CSV, HEADER, DELIMITER ',')&quot;
  with connection.cursor() as cur:
      sql = cur.mogrify(sql, params)
      cur.copy_expert(sql, file)
  </code></pre>