I have a Django Rest Framework view that generates python-docx objects, and I want to save such files in a model. I read in the documentation of python-docx that you can specify a "file-like" object to save the object, but I don't understand what it means.
This is my view:
class RoomingWordView(viewsets.ViewSet):
    def list(self, request, *args, **kwargs):
        ... some code
        documents_to_return = self.get_hotel_document(start_date, end_date, confirmed, hotel, bookings)
        return Response(documents_to_return)
    def get_hotel_document(self, start_date, end_date, confirmed, hotel, bookings):
        from django.core.files import File
        from docx import Document
        from docx.shared import Inches, Pt
        document = Document()
        section = document.sections[-1]
        section.left_margin = Inches(0.5)
        section.right_margin = Inches(0.5)
        style = document.styles['Normal']
        font = style.font
        font.name ='Arial'
        font.size = Pt(10)
        document.add_heading("MY COMPANY")
        if confirmed:
            document.add_paragraph("ROOMING LIST DEL 01-12-2018 AL 31-01-2019 INCLUYE RESERVAS CONFIRMADAS")
        else:
            document.add_paragraph("ROOMING LIST DEL 01-12-2018 AL 31-01-2019")
        document.add_paragraph("Hotel: {}".format(hotel))
        table = document.add_table(rows=len(bookings), cols=10)
        hdr_cells = table.rows[0].cells
        hdr_cells[0].text = 'Booking'
        hdr_cells[1].text = 'Reservado a'
        hdr_cells[2].text = '# Pax'
        hdr_cells[3].text = 'Agencia'
        hdr_cells[4].text = 'Habs'
        hdr_cells[5].text = 'Hab./Plan'
        hdr_cells[6].text = 'Entrada'
        hdr_cells[7].text = 'Salida'
        hdr_cells[8].text = 'Confirmación'
        hdr_cells[9].text = 'Producción'
        for cell in table.rows[0].cells:
            paragraphs = cell.paragraphs
            for paragraph in paragraphs:
                for run in paragraph.runs:
                    run.underline = True
        for booking in bookings['bookings']:
            row_cells = table.add_row().cells
            row_cells[0].text = booking['booking']
            row_cells[1].text = "\n".join(booking['people'])
            row_cells[2].text = booking['pax']
            row_cells[3].text = booking['agency']
            row_cells[4].text = booking['rooms']
            row_cells[5].text = "{}\n{}".format(booking['room_type'], booking['plan_type'])
            row_cells[6].text = booking['check_in']
            row_cells[7].text = booking['check_out']
            row_cells[8].text = booking['confirmation']
            row_cells[9].text = str(booking['production'])
        for row in table.rows:
            for cell in row.cells:
                paragraphs = cell.paragraphs
                for paragraph in paragraphs:
                    for run in paragraph.runs:
                        font = run.font
                        font.size = Pt(8)
        file_object = "rooming_reports/Rooming {} {}-{}.docx".format(hotel, start_date, end_date)
        document.save(file_object)
        return file_object
I want the view to save the resulting document object in a model called RoomingWordDocument, instead of saving it as a file, but I don't know how to assign document variable to RoomingWordDocument.file field.
 
    