title: Django how to check if user uploaded an image file when saving model with ImageField?
body: <p>I am looking for a way to resize, compress, and optimize the uploaded image when saving an ImageField.</p>
  
  <pre><code>class Image(models.Model):
      name = models.CharField(max_length=254, blank=True)
      caption = models.TextField(max_length=1000, blank=True)
      height = models.IntegerField()
      width = models.IntegerField()
      image = models.ImageField(upload_to='', height_field='height', width_field='width', storage=S3MediaStorage())
  </code></pre>
  
  <p>My first thought was to override the model's <code>save()</code> and implement this logic there, but I don't want the resize/compression/optimization to run again if the user doesn't update the image file (i.e. if he only updates <code>name</code> or <code>caption</code> on an existing object and saves it).</p>
  
  <ol>
  <li><p>What is a proper way to check when a new image file is uploaded to the ImageField, but not when the user only changes another field in the Model, eg. the user updates <code>caption</code> but leaves everything else as-is?</p></li>
  <li><p>How can the uploaded image file be accessed in code? I.e. what is the variable that contains the actual image file that can be passed to Pillow?</p></li>
  </ol>
  
  <p>edit: This is unique from <a href="https://stackoverflow.com/questions/1355150/django-when-saving-how-can-you-check-if-a-field-has-changed">the suspected duplicate</a>. I am not asking if the field has changed, because that would always cause false positives. I am asking if the user has uploaded an image file, which I will immediately change (resize/optimize/compress), so if the user immediately downloads his uploaded image he'll find that has a different binary with a randomly generated filename, and therefore comparing the filename or binary are not valid methods to determine if the user is uploading a different image.</p>