Django: generate a CSV file and store it into FileField

If anyone comes to this post like me and is wondering how to save a csv file directly into a models.FileField i recommend this way:

import csv
from io import StringIO
from django.core.files.base import ContentFile

row = ["Name", "Location", "Price"]

csv_buffer = StringIO()
csv_writer = csv.writer(csv_buffer)
csv_writer.writerow(row)

csv_file = ContentFile(csv_buffer.getvalue().encode('utf-8'))

bill.bill.save('output.csv', csv_file)