Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- class Profile(models.Model):
- user = models.OneToOneField(CreativeUser, on_delete=models.CASCADE, related_name='profile')
- slug = models.SlugField(unique=True, blank=True)
- full_name = models.CharField('Full name', max_length=200, blank=True)
- image = models.ImageField(upload_to=photo_directory_path, blank=True)
- job = models.CharField(max_length=200, blank=True)
- location = models.CharField(max_length=200, blank=True)
- about = models.TextField(max_length=5000, blank=True)
- def save(self, *args, **kwargs):
- try:
- profile = Profile.objects.get(id=self.id)
- if profile:
- if profile.image.name != self.image.name:
- profile.image.delete(save=False)
- except Exception as e:
- print(e)
- pass
- super().save(*args, **kwargs)
- if self.image:
- image_path = self.image.path
- img = Image.open(image_path)
- if img.size[0] > 300 or img.size[1] > 300:
- img.thumbnail((300, 300))
- img.save(image_path)
- def __str__(self):
- return self.user.email
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement