1
0
clubhaus-schornbach/clubhaus/homepage/models.py

71 lines
2.2 KiB
Python
Raw Normal View History

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)
def __str__(self):
return f"{self.name}"
class EventDateVotes(models.Model):
2022-08-03 02:07:44 +02:00
voter = models.ForeignKey(to="VotingUser", on_delete=models.CASCADE)
date = models.ForeignKey(to="EventDate", to_field="date", on_delete=models.CASCADE)
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)
class Meta:
constraints = [
2022-08-03 02:07:44 +02:00
models.UniqueConstraint(fields=("name", "modify_key"), name="unique_name_modify_key")
]
def __str__(self):
return f"{self.name} ({self.id})"