diff --git a/fiesta/apps/events/models/__init__.py b/fiesta/apps/events/models/__init__.py index 1c2b9345..3cfe1c4e 100644 --- a/fiesta/apps/events/models/__init__.py +++ b/fiesta/apps/events/models/__init__.py @@ -3,7 +3,7 @@ from .organizer import Organizer from .participant import Participant from .place import Place -from .price import PriceVariant +from .price_variant import PriceVariant diff --git a/fiesta/apps/events/models/price.py b/fiesta/apps/events/models/price_variant.py similarity index 85% rename from fiesta/apps/events/models/price.py rename to fiesta/apps/events/models/price_variant.py index 4edbc68f..b310475a 100644 --- a/fiesta/apps/events/models/price.py +++ b/fiesta/apps/events/models/price_variant.py @@ -17,8 +17,8 @@ class EventPriceVariantType(TextChoices): WITH_ESN_CARD = "with_esn_card", _("With ESN card") def is_available(self, variant: PriceVariant, user: User): - to_ = variant.to_ - from_ = variant.from_ + to_ = variant.available_to + from_ = variant.available_from if from_ is not None and from_ is not "" and from_ < datetime.now(): return False @@ -37,7 +37,6 @@ def is_available(self, variant: PriceVariant, user: User): class PriceVariant(BaseModel): title = models.CharField( max_length=256, - unique=True, verbose_name=_("title"), help_text=_("full name of the price"), ) @@ -51,17 +50,19 @@ class PriceVariant(BaseModel): related_name="price_variant", on_delete=models.CASCADE, verbose_name=_("event"), + null=True, + db_index=True, ) - from_ = models.DateTimeField( - verbose_name=_("from"), + available_from = models.DateTimeField( + verbose_name=_("available from"), help_text=_("From when users can purchase for this price."), null=True, blank=True, ) - to_ = models.DateTimeField( - verbose_name=_("to"), + available_to = models.DateTimeField( + verbose_name=_("available to"), help_text=_("Until when users can purchase for this price."), null=True, blank=True, @@ -73,6 +74,9 @@ class PriceVariant(BaseModel): default=dict, ) + class Meta: + unique_together = (("title", "event"),) + __all__ = ["PriceVariant"]