2022-07-30 13:58:57 +02:00
|
|
|
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()
|
|
|
|
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):
|
2022-07-31 23:17:09 +02:00
|
|
|
return f"{self.event.name} - {self.date.date().isoformat()}"
|
2022-07-30 13:58:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ClubhausEvent(models.Model):
|
|
|
|
name = models.CharField(max_length=200, blank=True)
|
|
|
|
date = models.DateTimeField(blank=True, null=True)
|
2022-07-31 23:17:09 +02:00
|
|
|
active = models.BooleanField(default=False)
|
2022-07-30 13:58:57 +02:00
|
|
|
location = models.TextField(blank=True)
|
|
|
|
beverages = models.TextField(blank=True)
|
|
|
|
food = models.TextField(blank=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"{self.name}"
|
2022-07-31 23:17:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
class EventDateVotes(models.Model):
|
2022-08-03 02:07:44 +02:00
|
|
|
voter = models.ForeignKey(to="VotingUser", on_delete=models.CASCADE)
|
2022-07-31 23:17:09 +02:00
|
|
|
date = models.ForeignKey(to="EventDate", to_field="date", on_delete=models.CASCADE)
|
2022-08-06 01:09:51 +02:00
|
|
|
available = models.BooleanField()
|
2022-08-03 02:07:44 +02:00
|
|
|
|
|
|
|
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)
|
2022-07-31 23:17:09 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
constraints = [
|
2022-08-03 02:07:44 +02:00
|
|
|
models.UniqueConstraint(fields=("name", "modify_key"), name="unique_name_modify_key")
|
2022-07-31 23:17:09 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def __str__(self):
|
2022-08-06 01:09:51 +02:00
|
|
|
return f"{self.name} ({self.id})"
|