Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
748 B
8
Indexable
Never
from django.db import models
from django.contrib.auth.hashers import make_password
from django.core.validators import MinLengthValidator, validate_email

class UserProfile(models.Model):
    username = models.CharField(max_length=100, unique=True, validators=[MinLengthValidator(3)])
    email = models.EmailField(unique=True, validators=[validate_email])
    password = models.CharField(max_length=128)  # Store password hash, not plaintext

    def save(self, *args, **kwargs):
        print(f"Saving UserProfile: username={self.username}, email={self.email}")
        # Hash the password before saving
        self.password = make_password(self.password)
        super().save(*args, **kwargs)

    def __str__(self):
        return self.username
Leave a Comment