создание проекта
This commit is contained in:
0
users/__init__.py
Normal file
0
users/__init__.py
Normal file
3
users/admin.py
Normal file
3
users/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
users/apps.py
Normal file
6
users/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UsersConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'users'
|
33
users/managers.py
Normal file
33
users/managers.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django.contrib.auth.base_user import BaseUserManager
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class CustomUserManager(BaseUserManager):
|
||||
"""
|
||||
Custom user model manager where email is the unique identifiers
|
||||
for authentication instead of usernames.
|
||||
"""
|
||||
def create_user(self, login, password, **extra_fields):
|
||||
"""
|
||||
Create and save a user with the given email and password.
|
||||
"""
|
||||
if not login:
|
||||
raise ValueError(_("The login must be set"))
|
||||
user = self.model(login=login, **extra_fields)
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
return user
|
||||
|
||||
def create_superuser(self, email, password, **extra_fields):
|
||||
"""
|
||||
Create and save a SuperUser with the given email and password.
|
||||
"""
|
||||
extra_fields.setdefault("is_staff", True)
|
||||
extra_fields.setdefault("is_superuser", True)
|
||||
extra_fields.setdefault("is_active", 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(email, password, **extra_fields)
|
0
users/migrations/__init__.py
Normal file
0
users/migrations/__init__.py
Normal file
22
users/models.py
Normal file
22
users/models.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .managers import CustomUserManager
|
||||
|
||||
|
||||
class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||
login = models.CharField(16, unique=True)
|
||||
is_staff = models.BooleanField(default=False)
|
||||
is_active = models.BooleanField(default=True)
|
||||
date_joined = models.DateTimeField(default=timezone.now)
|
||||
|
||||
USERNAME_FIELD = "login"
|
||||
REQUIRED_FIELDS = []
|
||||
|
||||
objects = CustomUserManager()
|
||||
|
||||
def __str__(self):
|
||||
return self.login
|
||||
|
Reference in New Issue
Block a user