0

The admin is able to upload an image but I would like to restrict it to only being a square image.

Here is my models.py file:

class Author(models.Model):
    author_name = models.CharField(max_length=200)
    author_image = models.ImageField(upload_to=upload_location,
        null=True, 
        blank=True,)
    author_bio = models.TextField()

    def __str__(self):
        return self.author_name
Chris
  • 363
  • 5
  • 20

1 Answers1

0

ImageField has height_field and width_field properties, but according to the docs, those only get auto-populated after the image is saved.

In order to do it before the image is uploaded, I think you're going to need jQuery. Check out this question/answer, as it seems like what you want to do. You would alter that code to compare that width == height to check for perfect squareness. AJAX would give you the option of the user uploading the image without the page needing to reload.

Supra621
  • 146
  • 3
  • 12