Enhance User model: add email field with unique constraint, update id_card field to allow null values, and include verified field. Update UserAdmin to display verified field. Improve device listing to filter by logged-in user.
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 2m39s

This commit is contained in:
2025-03-28 22:25:30 +05:00
parent ddfbeba2f4
commit 43f9b7ef7c
9 changed files with 145 additions and 59 deletions

View File

@ -1,20 +1,23 @@
from django.contrib.auth.models import BaseUserManager
from typing import Optional
from django.contrib.auth.models import UserManager as BaseUserManager
class CustomUserManager(BaseUserManager):
def create_user(self, username, password=None, **extra_fields):
def create_user(
self, username, email=None, password: Optional[str] = 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 = self.model(username=username, email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, username, password=None, **extra_fields):
def create_superuser(self, username, email=None, 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)
extra_fields.setdefault("is_staff", True)
extra_fields.setdefault("is_superuser", True)
return self.create_user(username, password, **extra_fields)