Django error in Cutom user model save() method

Viewed 36

I have a custom user model which was working without error, later I add field for user image then I can do registration but unable to login.

I think there is error in the save() method.

I don't accept user image in registration page, but there is template for loggedin user to add later

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

class User(AbstractUser):
    email = models.EmailField(verbose_name='email' ,max_length=223,unique=True)
    photo = models.ImageField(upload_to='prof_pic', blank=True,null=True)
    phone=models.CharField(null=True,max_length=11)
    REQUIRED_FIELDS = [ 'email','phone']



    def save(self,*args, **kwargs):
        super().save()
        if self.photo:
            pic = Image.open(self.photo.path)
            if pic.height > 300 or pic.width > 300:
                output_size = (300, 300)
                pic.thumbnail(output_size)
                pic.save(self.photo.path)
            super(User, self).save(*args, **kwargs)        

ERROR WHEN LOGGING IN

Please enter a correct username and password. Note that both fields may be case-sensitive.
1 Answers
Related