mirror of
https://github.com/Rushilwiz/NewViewsNews.git
synced 2025-04-11 07:30:17 -04:00
29 lines
854 B
Python
29 lines
854 B
Python
# 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-pfp.jpg', upload_to='profile_pics')
|
|
gaveValues = models.BooleanField(default=False)
|
|
economicScore = models.IntegerField(default=True,blank=True)
|
|
socialScore = models.IntegerField(default=True,blank=True)
|
|
|
|
|
|
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)
|