mirror of
https://github.com/Rushilwiz/NewViewsNews.git
synced 2025-04-16 17:50:16 -04:00
26 lines
698 B
Python
26 lines
698 B
Python
from django.db import models
|
|
|
|
# Create your models here.
|
|
|
|
from django.db import models
|
|
from django.contrib.auth.models import User
|
|
from PIL import Image
|
|
|
|
|
|
class Profile(models.Model):
|
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
|
profile_pic = 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.profile_pic.path)
|
|
|
|
if img.height > 300 or img.width > 300:
|
|
output_size = (300, 300)
|
|
img.thumbnail(output_size)
|
|
img.save(self.profile_pic.path)
|