add note to event model

This commit is contained in:
Maxime Bloch 2020-07-25 02:33:42 +02:00
parent 19d791153c
commit 1aaa3f68d4
2 changed files with 20 additions and 11 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 3.0.8 on 2020-07-25 00:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0002_auto_20200722_1803'),
]
operations = [
migrations.AddField(
model_name='event',
name='note',
field=models.TextField(default='', max_length=1024),
),
]

View file

@ -1,5 +1,4 @@
from django.db import models from django.db import models
from django.db.models import Q
from users.models import CustomUser from users.models import CustomUser
@ -14,28 +13,23 @@ class Event(models.Model):
date = models.DateField() date = models.DateField()
time = models.IntegerField(choices=TIME_SLOTS.items(), default=MORNING) time = models.IntegerField(choices=TIME_SLOTS.items(), default=MORNING)
capacity = models.IntegerField(default=6) capacity = models.IntegerField(default=6)
note = models.TextField(max_length=1024, default="")
def __str__(self): def __str__(self):
return f"{self.date} {self.TIME_SLOTS[self.time]}" return f"{self.date} {self.TIME_SLOTS[self.time]}"
def time_str(self): def time_str(self):
return Event.TIME_SLOTS[self.time] return Event.TIME_SLOTS[self.time]
def count_with_status(self, status): def count_with_status(self, status):
return self.eventregistration_set.filter(state=status).count() return self.eventregistration_set.filter(state=status).count()
def count_interested(self): def count_interested(self):
return self.count_with_status(EventRegistration.INTERESTED) return self.count_with_status(EventRegistration.INTERESTED)
def count_admitted(self): def count_admitted(self):
return self.count_with_status(EventRegistration.ADMITTED) return self.count_with_status(EventRegistration.ADMITTED)
def registration_of(self, user): def registration_of(self, user):
if not user.is_authenticated: if not user.is_authenticated:
return None return None
@ -49,7 +43,7 @@ class Event(models.Model):
class EventRegistration(models.Model): class EventRegistration(models.Model):
INTERESTED = "I" INTERESTED = "I"
ADMITTED = "A" ADMITTED = "A"
REGISTRATION_STATE = { REGISTRATION_STATE = {
INTERESTED: "op wachtlijst", INTERESTED: "op wachtlijst",
ADMITTED: "bevestigd", ADMITTED: "bevestigd",
@ -58,7 +52,6 @@ class EventRegistration(models.Model):
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE) user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
state = models.CharField(max_length=1, choices=REGISTRATION_STATE.items()) state = models.CharField(max_length=1, choices=REGISTRATION_STATE.items())
class Meta: class Meta:
constraints = [ constraints = [
models.UniqueConstraint( models.UniqueConstraint(
@ -66,10 +59,8 @@ class EventRegistration(models.Model):
), ),
] ]
def __str__(self): def __str__(self):
return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]" return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]"
def state_str(self): def state_str(self):
return EventRegistration.REGISTRATION_STATE[self.state] return EventRegistration.REGISTRATION_STATE[self.state]