mamweb/framadate/models.py

59 lines
2.1 KiB
Python

from django.db import models
from datetime import datetime
# Create your models here
class Framadate(models.Model):
name = models.TextField()
"isRelevant if all dates are in the future"
@property
def isRelevant(self):
for day in self.days_set.all():
if day.day < datetime.now().date():
return False
return True
def __str__(self):
return self.name
class NameInFramadate(models.Model):
framadate = models.ForeignKey(Framadate, on_delete=models.CASCADE, related_name="names_set")
name = models.CharField(max_length=200)
def __str__(self):
return self.name + " - in - " + self.framadate.name
class FramadateDate(models.Model):
framadate = models.ForeignKey(Framadate, on_delete=models.CASCADE, related_name="days_set")
day = models.DateField()
time = models.TimeField(null=True, blank=True)
def __str__(self):
return self.day.strftime("%Y-%m-%d") + " - in- " + self.framadate.name
class Meta:
ordering = ['day', 'time']
class Choice(models.IntegerChoices):
UNKNOWN = 0
YES = 3
NO = 2
MAYBE = 1
# Quirk -> name and framadateDate needs to share same Framadate...
class Record(models.Model):
nameInFramadate = models.ForeignKey(NameInFramadate, on_delete=models.CASCADE, related_name="records_set")
framadateDate = models.ForeignKey(FramadateDate, on_delete=models.CASCADE, related_name="records_set")
choice = models.IntegerField(choices=Choice.choices, default=Choice.UNKNOWN)
@property
def choiceName(self):
return Choice(self.choice).name
def __str__(self):
if self.framadateDate.time:
return self.nameInFramadate.name + " - in - " + self.framadateDate.framadate.name + " - " + self.framadateDate.day.strftime("%Y-%m-%d") + " - " + self.framadateDate.time.strftime("%H") + ":00 - " + Choice(self.choice).name
return self.nameInFramadate.name + " - in - " + self.framadateDate.framadate.name + " - " + self.framadateDate.day.strftime("%Y-%m-%d") + " - " + Choice(self.choice).name
class Meta:
ordering = ['framadateDate__day', 'framadateDate__time']