Saving BytesIO to Django ImageField
<p>I have a web scraper that I want to download an image of the page it's scraping and save it as a "screenshot" ImageField in a Django model. I am using this code:</p>

<pre><code>def save_screenshot(source,screenshot):
    box = (0, 0, 1200, 600)
    im = Image.open(io.BytesIO(screenshot))
    region = im.crop(box)
    tempfile_io = io.BytesIO()
    region.save(tempfile_io, 'JPEG', optimize=True, quality=70)
    source.screenshot.save(source.slug_name+"-screenshot",ContentFile(tempfile_io.getvalue()),save=True)
</code></pre>

<p>It saves the screenshot to the /media/news_source_screenshots/ directory but doesn't save it to the model. The model field is defined as:</p>

<pre><code>screenshot = models.ImageField(upload_to='news_source_screenshots',blank=True,null=True)
</code></pre>

<p>What am I missing?</p>