Skip to content

Instantly share code, notes, and snippets.

@mansha99
Created July 4, 2023 17:12
Show Gist options
  • Save mansha99/ef1d1ecce52912dce4f5de431f1671cd to your computer and use it in GitHub Desktop.
Save mansha99/ef1d1ecce52912dce4f5de431f1671cd to your computer and use it in GitHub Desktop.
notice_app/notices/managers.py
from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import gettext_lazy as _
class CustomUserManager(BaseUserManager):
def create_user(self, mobile, password, **extra_fields):
if not mobile:
raise ValueError(_("The mobile must be set"))
user = self.model(mobile=mobile, **extra_fields)
user.set_password(password)
user.save()
return user
def create_superuser(self, mobile, password, **extra_fields):
extra_fields.setdefault("is_superuser", True)
extra_fields.setdefault("is_active", True)
if extra_fields.get("is_superuser") is not True:
raise ValueError(_("Superuser must have is_superuser=True."))
return self.create_user(mobile, password, **extra_fields)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment