2025.09.14-18:02:28

This commit is contained in:
2025-09-14 18:02:28 +02:00
parent 565ef0cad1
commit ff37c9cd8b
32 changed files with 733 additions and 22 deletions

29
user/managers.py Normal file
View File

@@ -0,0 +1,29 @@
from django.contrib.auth.models import BaseUserManager
from django.utils.translation import gettext as _
class UserProfileManager(BaseUserManager):
def create_user(self,username:str, email:str,password=None,**extra_fields):
if not email:
raise ValueError(_("The email must be set!"))
if not username:
raise ValueError(_("Username must be set!"))
email = self.normalize_email(email)
user = self.model(username=username,email=email,**extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, username:str, email:str, password=None,**extra_fields):
extra_fields.setdefault('is_staff',True)
extra_fields.setdefault('is_superuser',True)
if extra_fields.get('is_staff') is not True:
raise ValueError(_("Superuser must have is_staff=True"))
if extra_fields.get('is_superuser') is not True:
raise ValueError(_("Superuser must have is_superuser=True"))
return self.create_user(username,email,password,**extra_fields)