mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-28 09:50:05 +00:00
Initial commit
This commit is contained in:
20
api/managers.py
Normal file
20
api/managers.py
Normal file
@ -0,0 +1,20 @@
|
||||
from django.contrib.auth.models import BaseUserManager
|
||||
|
||||
|
||||
class CustomUserManager(BaseUserManager):
|
||||
def create_user(self, username, password=None, **extra_fields):
|
||||
"""Create and return a user with an email and password."""
|
||||
if not username:
|
||||
raise ValueError("The Username field must be set")
|
||||
|
||||
user = self.model(username=username, **extra_fields)
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_superuser(self, username, password=None, **extra_fields):
|
||||
"""Create and return a superuser with an email and password."""
|
||||
extra_fields.setdefault('is_staff', True)
|
||||
extra_fields.setdefault('is_superuser', True)
|
||||
|
||||
return self.create_user(username, password, **extra_fields)
|
Reference in New Issue
Block a user