from decimal import Decimal from django.db import models from apps.common.models import TimeStampedModel class SiteSettings(models.Model): """Singleton with store-wide settings editable from the admin.""" site_name = models.CharField("название сайта", max_length=255, default="HOMM") phone = models.CharField("телефон", max_length=32, blank=True) email = models.EmailField("email", blank=True) address = models.CharField("адрес", max_length=500, blank=True) working_hours = models.CharField("часы работы", max_length=255, blank=True) telegram_url = models.URLField("Telegram", blank=True) vk_url = models.URLField("ВКонтакте", blank=True) whatsapp_url = models.URLField("WhatsApp", blank=True) free_delivery_threshold = models.DecimalField( "бесплатная доставка от", max_digits=12, decimal_places=2, default=Decimal("0") ) default_delivery_cost = models.DecimalField( "стоимость доставки", max_digits=12, decimal_places=2, default=Decimal("0") ) bonus_accrual_percent = models.DecimalField( "процент начисления бонусов", max_digits=5, decimal_places=2, default=Decimal("0") ) bonus_max_payment_percent = models.DecimalField( "максимум оплаты бонусами, %", max_digits=5, decimal_places=2, default=Decimal("0") ) bonus_ttl_days = models.PositiveIntegerField("срок жизни бонусов, дней", default=365) privacy_policy_url = models.URLField("политика конфиденциальности", blank=True) offer_url = models.URLField("публичная оферта", blank=True) updated_at = models.DateTimeField(auto_now=True) class Meta: db_table = "content_site_settings" verbose_name = "настройки сайта" verbose_name_plural = "настройки сайта" def __str__(self) -> str: return "Настройки сайта" def save(self, *args, **kwargs): self.pk = 1 super().save(*args, **kwargs) @classmethod def load(cls) -> "SiteSettings": obj, _ = cls.objects.get_or_create(pk=1) return obj class StaticPage(TimeStampedModel): slug = models.SlugField("адрес", max_length=255, unique=True) title = models.CharField("заголовок", max_length=255) content = models.TextField("содержимое", blank=True) seo_title = models.CharField("SEO title", max_length=255, blank=True) seo_description = models.CharField("SEO description", max_length=500, blank=True) is_published = models.BooleanField("опубликована", default=True) class Meta: db_table = "content_static_page" verbose_name = "статическая страница" verbose_name_plural = "статические страницы" ordering = ["title"] def __str__(self) -> str: return self.title def save(self, *args, **kwargs): if not self.slug: from apps.common.utils import make_slug self.slug = make_slug(self.title) super().save(*args, **kwargs) class Banner(TimeStampedModel): class Position(models.TextChoices): HOME_TOP = "home_top", "Главная — верх" HOME_MIDDLE = "home_middle", "Главная — середина" CATEGORY = "category", "Категория" title = models.CharField("название", max_length=255) image_url = models.URLField("изображение", max_length=1000) link_url = models.URLField("ссылка", max_length=1000, blank=True) position = models.CharField( "позиция", max_length=20, choices=Position.choices, default=Position.HOME_TOP ) is_active = models.BooleanField("активен", default=True) sort_order = models.IntegerField("порядок", default=0) starts_at = models.DateTimeField("начало показа", null=True, blank=True) ends_at = models.DateTimeField("конец показа", null=True, blank=True) class Meta: db_table = "content_banner" verbose_name = "баннер" verbose_name_plural = "баннеры" ordering = ["sort_order", "-created_at"] def __str__(self) -> str: return self.title