Why does my Django Model not work correctly?
Currently making a basic django project, following a well set out tutorial off youtube. All's going well and I usually try to debug isses myself and I wouldn't be asking if i was stuck.
Issue:
This code is meant to check the image size onces it's reuploaded and then format to make it square but looking at the image linked, this isnt the case. Is my code wrong? is there another way to check and validate images?
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default="default.jpg", upload_to="profile_pics")
def __str__(self):
return f'{self.user.username} Profile'
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
img = Image.open(self.image.path)
if img.height > 300 or img.width > 300:
output_size = (300,300)
img.thumbnail(output_size)
img.save(self.image.path)
from Recent Questions - Stack Overflow https://ift.tt/2WOp1lq
https://ift.tt/eA8V8J
Comments
Post a Comment