login route

This commit is contained in:
Timofey
2025-08-29 14:44:26 +03:00
parent d314303066
commit 5a06a625fb
11 changed files with 701 additions and 5 deletions

View File

@@ -1,3 +1,56 @@
from django.contrib.auth.models import User
from django.db import models
from django.db.models.fields.related import OneToOneField
from typing import Optional
import uuid
# Create your models here.
from sitemanagement.constants.account_types import account_types, AccountType, AccountTypeLiteral
class UserProfile(models.Model):
"""
Профиль пользователя с дополнительной информацией
"""
def get_account_type_display(self) -> str:
"""Автоматически добавляется Django для полей с choices"""
...
user: OneToOneField[User] = models.OneToOneField(
User,
on_delete=models.CASCADE,
related_name='userprofile'
)
uuid: models.UUIDField = models.UUIDField(
default=uuid.uuid4,
editable=False,
unique=True,
null=True
)
account_type: models.CharField = models.CharField(
max_length=10,
verbose_name="Тип аккаунта",
choices=account_types,
db_index=True
)
imageURL: models.CharField = models.CharField(
max_length=255,
null=True,
blank=True,
verbose_name="URL изображения профиля"
)
class Meta:
verbose_name = "Профиль пользователя"
verbose_name_plural = "Профили пользователей"
def __str__(self) -> str:
return f"{self.user.first_name} ({self.get_account_type_display()})"
@property
def short_uuid(self) -> Optional[str]:
"""Возвращает первые 6 символов UUID или None, если UUID не установлен"""
return str(self.uuid)[:6] if self.uuid else None
def get_account_type(self) -> AccountTypeLiteral:
"""Возвращает тип аккаунта пользователя"""
return AccountType(self.account_type).value