Error updating form with ImageField [closed]

0

Registering a new record with uploaded saves normally, but updating shows the following error:

I gave a print in the var picture and when I register a new sample image.png, but when updating it will be directory / image.png.

    
asked by anonymous 09.09.2016 / 12:32

1 answer

0
    def clean_image(self):
      picture = self.cleaned_data.get("image")
      try:
          if picture:
              w, h = get_image_dimensions(picture)
              if not picture.content_type in "image/png, image/jpg, image/jpeg":
                  raise forms.ValidationError('Permitido apenas os formatos: *.jpg, *.jpeg, *.png.')
              if w > 200 or h > 200:
                  raise forms.ValidationError('Imagem muito grande, o tamanho tem que ser ' + str(200) + 'px * ' + str(200) + 'px.')
      except AttributeError:
          """
          Handles case when we are updating the user profile
          and do not supply a new avatar
          """
          pass
      return picture

I was able to resolve it that way.

    
09.09.2016 / 17:57