title: Django: Accessing ImageField in clean()/save() at creation time and updates
body: <p>I have a model in Django which has a lot of computed fields, it looks like this:</p>
  
  <pre><code>class Media(models.Model):
      titel = models.CharField(max_length=128)
      datei = models.ImageField(upload_to='usermedia/%Y/')
  
      # automatically calculated fields
      width = models.PositiveIntegerField(editable=False)
      height = models.PositiveIntegerField(editable=False)
      imagetype = models.CharField(editable=False, max_length=32)
      thumbnail_b64 = models.CharField(
          editable=False, max_length=4096)
  
      def clean(self):
          self.width = self.datei.width
          self.height = self.datei.height
  
          self.imagetype = magic.from_buffer(self.datei.read(), mime=True)
  
          buffer = BytesIO()
          img = Image.open(self.datei)
  
          img.thumbnail((32, 32))
          img.save(buffer, format="PNG")
  
          self.thumbnail_b64 = base64.b64encode(
              buffer.getvalue()).decode("utf-8")
  </code></pre>
  
  <p>Everything is good at a first glance - the model does what is meant to, at least at adding new Instances. But as soon as I try to <strong>update</strong> one instance, then Django raises an error:</p>
  
  <blockquote>
    <p>Exception Type:    ValueError
    Exception Value: read of closed file</p>
  </blockquote>
  
  <p>The problem seems to be <code>self.imagetype = magic.from_buffer(self.datei.read(), mime=True)</code>. I think <code>self.datei</code> is no longer in the memory, right?</p>
  
  <p>I therefore changed the <code>from_buffer</code> thingy from both parts into:</p>
  
  <pre><code>self.imagetype = magic.from_file(self.datei.path, mime=True)
  ...
  img = Image.open(self.datei.path)
  </code></pre>
  
  <p>Now I can finally update my model instances, but now, whenever I add new instances, I am getting a </p>
  
  <blockquote>
    <p><code>FileNotFoundError</code> </p>
  </blockquote>
  
  <p><strong>How would a solution look like that works for both, adding new entries and updating old ones?</strong></p>