title: How do I retrieve the row data from my Django database as a list?
body: <p>I would like to retrieve the data in my Django database table rows as a list so I can iterate over it and write each value of the list to an Excel spreadsheet. I tried doing this using dictionaries but dictionaries are not ordered in Python so my columns were getting all out of order. I need my Excel spreadsheet to look the same as my database table, not scrambled around in random order. How can I achieve this? </p>
  
  <p>Current code:</p>
  
  <pre><code>def dump_attorneys_to_xlsx(request):
      if request.GET.get('export'):
          output = BytesIO()
          workbook = xlsxwriter.Workbook(output, {'in_memory': True})
          worksheet = workbook.add_worksheet('Summary')
  
          attorneys = Attorney.objects.all().values()
          # Write header
          worksheet.write_row(0, 0, attorneys[0].keys())
          # Write data
          for row_index, row_dict in enumerate(attorneys, start=1):
              worksheet.write_row(row_index, 0, row_dict.values())
          workbook.close()
  
          output.seek(0)
  
          response = HttpResponse(output.read(), content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
          response['Content-Disposition'] = 'attachment; filename=summary.xlsx'
  </code></pre>