From 1aaa3f68d4f559711fbcf8359e9eae386a77499c Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Sat, 25 Jul 2020 02:33:42 +0200 Subject: [PATCH] add note to event model --- events/migrations/0003_event_note.py | 18 ++++++++++++++++++ events/models.py | 13 ++----------- 2 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 events/migrations/0003_event_note.py diff --git a/events/migrations/0003_event_note.py b/events/migrations/0003_event_note.py new file mode 100644 index 0000000..2193733 --- /dev/null +++ b/events/migrations/0003_event_note.py @@ -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), + ), + ] diff --git a/events/models.py b/events/models.py index 000c483..c5b1e0d 100644 --- a/events/models.py +++ b/events/models.py @@ -1,5 +1,4 @@ from django.db import models -from django.db.models import Q from users.models import CustomUser @@ -14,28 +13,23 @@ class Event(models.Model): date = models.DateField() time = models.IntegerField(choices=TIME_SLOTS.items(), default=MORNING) capacity = models.IntegerField(default=6) - + note = models.TextField(max_length=1024, default="") def __str__(self): return f"{self.date} {self.TIME_SLOTS[self.time]}" - def time_str(self): return Event.TIME_SLOTS[self.time] - def count_with_status(self, status): return self.eventregistration_set.filter(state=status).count() - def count_interested(self): return self.count_with_status(EventRegistration.INTERESTED) - def count_admitted(self): return self.count_with_status(EventRegistration.ADMITTED) - def registration_of(self, user): if not user.is_authenticated: return None @@ -49,7 +43,7 @@ class Event(models.Model): class EventRegistration(models.Model): INTERESTED = "I" - ADMITTED = "A" + ADMITTED = "A" REGISTRATION_STATE = { INTERESTED: "op wachtlijst", ADMITTED: "bevestigd", @@ -58,7 +52,6 @@ class EventRegistration(models.Model): user = models.ForeignKey(CustomUser, on_delete=models.CASCADE) state = models.CharField(max_length=1, choices=REGISTRATION_STATE.items()) - class Meta: constraints = [ models.UniqueConstraint( @@ -66,10 +59,8 @@ class EventRegistration(models.Model): ), ] - def __str__(self): return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]" - def state_str(self): return EventRegistration.REGISTRATION_STATE[self.state]