Not allowing images small than certain dimensions

I have a model that saves user profile images. If the image that is uploaded is greater than 200x200 pixels, then we resize to 200x200. If the image is right at 200x200, then we return that image. What I want now is to throw an error to the user saying that this image is too small and is not allowed. Here's what I have:

I have a model that saves user profile images. If the image that is uploaded is greater than 200x200 pixels, then we resize to 200x200. If the image is right at 200x200, then we return that image. What I want now is to throw an error to the user saying that this image is too small and is not allowed. Here's what I have:

class Profile(models.Model):
    GENDER_CHOICES = (
        ('M', 'Male'),
        ('F', 'Female'),
    )
    user    = models.OneToOneField(User, null=True, on_delete=models.CASCADE)
    bio     = models.CharField(max_length=200, null=True)
    avatar  = models.ImageField(upload_to="img/path")
    gender  = models.CharField(max_length=1, choices=GENDER_CHOICES, null=True)
def save(self, *args, **kwargs):
    super(Profile, self).save(*args, **kwargs)
    if self.avatar:
        image = Image.open(self.avatar)
        height, width = image.size
        if height == 200 and width == 200:
            image.close()
            return

        if height < 200 or width < 200:
            return ValidationError("Image size must be greater than 200")
        image = image.resize((200, 200), Image.ANTIALIAS)
        image.save(self.avatar.path)
        image.close()

When an image is smaller than 200px in width or height, the image should not be uploaded. However, the image is being uploaded. How can I stop this from happening?

Python Django Tutorial | Django Course

Python Django Tutorial | Django Course

🔥Intellipaat Django course: https://intellipaat.com/python-django-training/ 👉This Python Django tutorial will help you learn what is django web development &...

This Python Django tutorial will help you learn what is django web development & application, what is django and introduction to django framework, how to install django and start programming, how to create a django project and how to build django app. There is a short django project as well to master this python django framework.

Why should you watch this Django tutorial?

You can learn Django much faster than any other programming language and this Django tutorial helps you do just that. Our Django tutorial has been created with extensive inputs from the industry so that you can learn Django and apply it for real world scenarios.

Django

Well i used django ... i want to know after completing all the coding stuff, can i make all the codes online ?

Well i used django ... i want to know after completing all the coding stuff, can i make all the codes online ?

as Django give you a local host, i have a .com domain but can i integrate the codes to it so it works ?