Gets a PIL image ready to be able to be saved using
        :py:meth:`django.db.models.fields.files.FieldFile.save`

        It converts the mode first to ``RGB`` or ``L``, so that it can
        then save it as a ``JPEG``. It will save it as a progressive
        ``JPEG`` with a quality of :py:attr:`IMAGE_QUALITY`.

        :param pil_image: original image
        :type pil_image: :py:class:`PIL.Image.Image`
        :return: transformed image
        :rtype: :py:class:`django.core.files.base.ContentFile`

def pil_image_to_django_file(self, pil_image):
        '''
        Gets a PIL image ready to be able to be saved using
        :py:meth:`django.db.models.fields.files.FieldFile.save`

        It converts the mode first to ``RGB`` or ``L``, so that it can
        then save it as a ``JPEG``. It will save it as a progressive
        ``JPEG`` with a quality of :py:attr:`IMAGE_QUALITY`.

        :param pil_image: original image
        :type pil_image: :py:class:`PIL.Image.Image`
        :return: transformed image
        :rtype: :py:class:`django.core.files.base.ContentFile`
        '''
        if pil_image.mode not in ('L', 'RGB'):
            pil_image = pil_image.convert("RGB")
        temp_io = six.BytesIO()

        pil_image.save(
            temp_io,
            "JPEG",
            quality=self.IMAGE_QUALITY,
            optimize=True,
            progressive=True,
            icc_profile=pil_image.info.get('icc_profile')
        )

        temp_io.seek(0)
        django_file = ContentFile(temp_io.getvalue())
        return django_file