from django.db import models
from django.contrib.auth.models import User
from PIL import Image

class Profile(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    image = models.ImageField(default='default.jpg',
                              upload_to='profile_pic/')
                              

    def __str__(self):
        return f'{self.user.username} Profile'

    def save(self,*args,**kwargs):
        super().save()
        img = Image(self.prof_pic.path)
        if img.height > 300 and img.width > 300:
            output_size = (300,300)
            img.thumbnail(output_size)
            img.save(self.prof_pic.path)

        

[(6, 'django.db.models.ForeignKey', 'models.ForeignKey', False, 'from django.db import models\n'), (7, 'django.db.models.ImageField', 'models.ImageField', False, 'from django.db import models\n'), (16, 'PIL.Image', 'Image', False, 'from PIL import Image\n')]