title: How to save pillow image object to Django ImageField?
body: <p>Having a Django model for thumbnail image like:</p>
  
  <pre><code>class Thumb(models.Model):
      thumb = models.ImageField(upload_to='uploads/thumb/', null=True, default=None)
  </code></pre>
  
  <p>The view generates a thumbnail with the <a href="https://pillow.readthedocs.org/en/3.0.x/index.html" rel="noreferrer"><code>pillow</code></a> package, and should save this in a <code>Thumb</code> instance, using code like:</p>
  
  <pre><code>image.thumbnail((50, 50))
  inst.thumb.save('thumb.jpg', ???)
  </code></pre>
  
  <p>What is the right way to make <code>image</code> data for the <code>inst.thumb.save</code> at <code>???</code>?</p>
  
  <p>I was able to get the below to work:</p>
  
  <pre><code>thumb_temp = NamedTemporaryFile()
  image.save(thumb_temp, 'JPEG', quality=80)
  thumb_temp.flush()
  inst.thumb.save('thumb.jpg', File(thumb_temp))
  thumb_temp.close()  # Probably required to ensure temp file delete at close
  </code></pre>
  
  <p>But it seems rather clumsy to write a temporary file just to pass internal data to <code>inst.thumb.save</code>, so I wonder if there is a more elegant way to do it.  Documentation for <a href="https://code.djangoproject.com/wiki/NamedTemporaryFile" rel="noreferrer">Django class <code>NamedTemporaryFile</code></a>.</p>