Files
xvatayka/core/apps/accounts/models.py
Abdulaziz Axmadaliyev 3691e2d068 Initial commit
2026-02-17 19:05:54 +05:00

43 lines
1.2 KiB
Python

from django.contrib.auth import models as auth_models
from django.db import models
from .choices import RoleChoice
from .managers import UserManager
from ..management.models import Region, Warehouse
class User(auth_models.AbstractUser):
phone = models.CharField(max_length=255, unique=True)
username = models.CharField(max_length=255, null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
validated_at = models.DateTimeField(null=True, blank=True)
role = models.CharField(
max_length=255,
choices=RoleChoice,
default=RoleChoice.EMPLOYEE,
)
region = models.ForeignKey(
Region,
on_delete=models.SET_NULL,
null=True,
blank=True,
help_text="Faqat menejerlar uchun"
)
warehouse = models.ForeignKey(
Warehouse,
on_delete=models.PROTECT,
null=True,
blank=True,
help_text="Faqat xodimlar uchun"
)
def get_full_name(self):
return f"{self.first_name} {self.last_name}".strip() or self.phone
USERNAME_FIELD = "phone"
objects = UserManager()
def __str__(self):
return self.phone