Упрощение base.py: удаление неиспользуемого кода
- Удалён импорт неиспользуемых менеджеров (ActiveManager, SoftDeleteManager, SoftDeleteQuerySet) - Удалён неиспользуемый active_objects manager - Заменены хаки __import__ на нормальные импорты (slugify, unidecode) - Перенесён IntegrityError в импорты модуля - Добавлен TODO для унификации системы soft delete 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
"""
|
||||
Базовые модели для products приложения.
|
||||
Содержит SKUCounter и BaseProductEntity (абстрактный базовый класс).
|
||||
|
||||
TODO: Унификация системы soft delete
|
||||
- Перевести ProductCategory с is_deleted на status (как в BaseProductEntity)
|
||||
- Упростить managers.py, убрав поддержку старой системы is_deleted
|
||||
- Унифицировать ProductTag (добавить status или оставить is_active)
|
||||
"""
|
||||
from django.db import models, transaction
|
||||
from django.db import models, transaction, IntegrityError
|
||||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from .managers import ActiveManager, SoftDeleteManager, SoftDeleteQuerySet
|
||||
from django.utils.text import slugify
|
||||
from unidecode import unidecode
|
||||
|
||||
# Получаем User модель один раз для использования в ForeignKey
|
||||
User = get_user_model()
|
||||
@@ -140,9 +145,8 @@ class BaseProductEntity(models.Model):
|
||||
verbose_name="Архивировано пользователем"
|
||||
)
|
||||
|
||||
# Managers
|
||||
objects = models.Manager() # Все товары
|
||||
active_objects = models.Manager() # Будет переопределен ниже
|
||||
# Manager
|
||||
objects = models.Manager()
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
@@ -204,13 +208,11 @@ class BaseProductEntity(models.Model):
|
||||
Автогенерация slug из name если не задан.
|
||||
Использует transaction.atomic() и retry логику для обработки race condition.
|
||||
"""
|
||||
from django.db import transaction, IntegrityError
|
||||
from ..services.slug_service import SlugService
|
||||
|
||||
# Генерируем базовый slug
|
||||
if not self.slug or self.slug.strip() == '':
|
||||
transliterated_name = __import__('unidecode', fromlist=['unidecode']).unidecode(self.name)
|
||||
base_slug = __import__('django.utils.text', fromlist=['slugify']).slugify(transliterated_name)
|
||||
base_slug = slugify(unidecode(self.name))
|
||||
else:
|
||||
base_slug = self.slug
|
||||
|
||||
|
||||
Reference in New Issue
Block a user