#Abstract User

10 messages · Page 1 of 1 (latest)

verbal wolf
#

Trying to use abstract user to modify some fields of user, and i used it on my last project and it worked fine no problems at all, but now im having an error and i dont rememner doing anything else than just importing abstract user
models.py

from django.db import models
from PIL import Image
from django.core.exceptions import ValidationError

class User(AbstractUser):
    display_name = models.CharField(max_length=20, null=False, blank=False)
    profile_image = models.ImageField(null=True, blank=True, default='defaultProfile.jpg', upload_to='profiles/')
    email_verified = models.BooleanField(default=False) 
    bio = models.TextField(blank=True, null=True)
    birthdate = models.DateField


    def save(self, *args, **kwargs):
        # Override the save method to resize the image before saving it.
        super().save(*args, **kwargs)

        # Check if the profile image exists and resize it if necessary.
        if self.profile_image and hasattr(self.profile_image, 'path'):
            img_path = self.profile_image.path
            try:
                with Image.open(img_path) as img:
                    # Resize the image to exactly 225x225 pixels.
                    img = img.resize((225, 225), Image.ANTIALIAS)  # Use Image.ANTIALIAS for better quality resizing.
                    img.save(img_path, quality=100)  # Set quality to 100 for maximum quality.
            except Exception as e:
                # Handle the exception if any error occurs during image processing.
                print(f"Error resizing image: {str(e)}")
```https://i.gyazo.com/11583681e1ea78410ee790eba478407f.png
kind pumice
verbal wolf
kind pumice
#

Your base already seem to have a lot of migrations

#

If you haven't changed user at the start of the project, well, it's pretty messy

verbal wolf
#

yeah it works now after i deleted the migrations folder

kind pumice
#

You were dropping the whole DB?

#

NEVER delete applied migration files otherwise

#

Though in this case it's the easiest option (reset everything)