Features: 1) Add avatar_url property to User model.

Fixes: 1) Restore correct imports order in `engine/vibes_auth/models.py`.

Extra: 1) Adjust formatting and grouping for clarity in imports section.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-12-10 18:38:40 +03:00
parent 9fe433221a
commit d03b6b0ec9

View file

@ -6,20 +6,21 @@ from django.contrib.auth.models import Group as BaseGroup
from django.core.cache import cache from django.core.cache import cache
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db.models import ( from django.db.models import (
BooleanField,
CharField,
EmailField,
ImageField,
JSONField,
UUIDField,
ForeignKey,
TextField,
DateTimeField,
Index,
CASCADE, CASCADE,
SET_NULL, SET_NULL,
BooleanField,
CharField,
DateTimeField,
EmailField,
ForeignKey,
ImageField,
Index,
JSONField,
TextField,
UUIDField,
) )
from django.utils import timezone from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from rest_framework_simplejwt.token_blacklist.models import ( from rest_framework_simplejwt.token_blacklist.models import (
BlacklistedToken as BaseBlacklistedToken, BlacklistedToken as BaseBlacklistedToken,
@ -29,10 +30,10 @@ from rest_framework_simplejwt.token_blacklist.models import (
) )
from engine.core.abstract import NiceModel from engine.core.abstract import NiceModel
from engine.payments.models import Balance
from engine.vibes_auth.choices import SenderType, ThreadStatus from engine.vibes_auth.choices import SenderType, ThreadStatus
from engine.vibes_auth.managers import UserManager from engine.vibes_auth.managers import UserManager
from engine.vibes_auth.validators import validate_phone_number from engine.vibes_auth.validators import validate_phone_number
from engine.payments.models import Balance
class User(AbstractUser, NiceModel): # type: ignore [django-manager-missing] class User(AbstractUser, NiceModel): # type: ignore [django-manager-missing]
@ -98,6 +99,10 @@ class User(AbstractUser, NiceModel): # type: ignore [django-manager-missing]
# noinspection PyClassVar # noinspection PyClassVar
objects = UserManager() # type: ignore [misc, assignment] objects = UserManager() # type: ignore [misc, assignment]
@cached_property
def avatar_url(self):
return self.avatar.url
def add_to_recently_viewed(self, product_uuid): def add_to_recently_viewed(self, product_uuid):
recently_viewed = self.recently_viewed recently_viewed = self.recently_viewed
if product_uuid not in recently_viewed: if product_uuid not in recently_viewed: