from django.db import models # Create your models here. from django.utils import timezone class TobaccoCategory(models.Model): name = models.CharField(max_length=200, unique=True, blank=False, null=False) def __str__(self): return f"{self.name} ({self.id})" class Tobacco(models.Model): name = models.CharField(max_length=200, unique=True, blank=False, null=False) description = models.TextField(blank=True, null=False) category = models.ForeignKey("TobaccoCategory", on_delete=models.CASCADE, blank=False, null=False) in_stock = models.BooleanField(default=True) picture = models.ImageField(upload_to="tobacco_images/", null=False, blank=True) def __str__(self): return self.name class EventDate(models.Model): event = models.ForeignKey(to="ClubhausEvent", on_delete=models.CASCADE) date = models.DateTimeField(unique=True, default=timezone.now) def __str__(self): return f"{self.event.name} - {self.date.date().isoformat()}" class ClubhausEvent(models.Model): name = models.CharField(max_length=200, blank=True) date = models.DateTimeField(blank=True, null=True) active = models.BooleanField(default=False) voting_locked = models.BooleanField(default=False) location = models.TextField(blank=True) beverages = models.TextField(blank=True) food = models.TextField(blank=True) background_picture = models.ForeignKey(to="EventBackground", on_delete=models.DO_NOTHING, blank=True, null=True) def __str__(self): return f"{self.name}" class EventBackground(models.Model): name = models.CharField(max_length=200, blank=True) picture = models.ImageField(upload_to="event_backgrounds/", null=False, blank=True, ) def __str__(self): return f"{self.name} ({self.id})" class EventDateVote(models.Model): voter = models.ForeignKey(to="VotingUser", on_delete=models.CASCADE) date = models.ForeignKey(to="EventDate", to_field="date", on_delete=models.CASCADE) available = models.BooleanField() class Meta: constraints = [ models.UniqueConstraint(fields=("voter", "date"), name="unique_voter_day") ] def __str__(self): return f"{self.voter.name}({self.voter.id}) - {self.date.date.isoformat()}" class VotingUser(models.Model): name = models.CharField(max_length=200, blank=False) modify_key = models.CharField(max_length=200, blank=False) class Meta: constraints = [ models.UniqueConstraint(fields=("name", "modify_key"), name="unique_name_modify_key") ] def __str__(self): return f"{self.name} ({self.id})" class Setting(models.Model): active = models.BooleanField(default=True) name = models.CharField(max_length=200, default="Default Settings", blank=False) intro_text = models.TextField(blank=True) intro_text_classes = models.CharField(max_length=500, default="text-center fs-5", blank=True, help_text="Extra CSS classes for the div for the intro text like text size") spotify_playlist_url = models.CharField(max_length=500, blank=True, help_text="The link to the Spotify playlist") class Meta: constraints = [ models.UniqueConstraint(fields=("name",), name="unique_name") ] def __str__(self): return f"{self.id} - {self.name}"