from django.db import models # Create your models here. class ShopConfiguration(models.Model): name = models.CharField(max_length=100, default="Shop name", unique=True) zasilkovna_shipping_price = models.DecimalField(max_digits=10, decimal_places=2, default=50) zasilkovna_address_id = models.CharField(max_length=100, blank=True, null=True, help_text="ID výdejního místa Zásilkovny pro odesílání zásilek") free_shipping_over = models.DecimalField(max_digits=10, decimal_places=2, default=2000) class CURRENCY(models.TextChoices): CZK = "CZK", "Czech Koruna" EUR = "EUR", "Euro" currency = models.CharField(max_length=10, default=CURRENCY.CZK, choices=CURRENCY.choices) class Meta: verbose_name = "Shop Configuration" verbose_name_plural = "Shop Configuration" def save(self, *args, **kwargs): # zajištění singletonu self.pk = 1 super().save(*args, **kwargs) @classmethod def get_solo(cls): obj, _ = cls.objects.get_or_create(pk=1) return obj