The user model is as follows.
class User(AbstractUser): username = None email = models.EmailField('email address', unique=True) first_name = models.CharField('First Name', max_length=255, blank=True, null=False) last_name = models.CharField('Last Name', max_length=255, blank=True, null=False) objects = UserManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = ['username']
The user profile model is as follows.
class UserProfile(models.Model): user = models.OneToOneField(User, related_name='profile', on_delete=models.CASCADE) avatar = models.ImageField(upload_to=avatar_image, blank=True, null=True)
P粉2686548732024-03-31 09:32:13
This makes sense. Please note that django uses the PIL
library to handle images
In your virtual environment
pip install pillow
In your models.py
from PIL import images
Images are handled as static files. Handling static files is described here