From 8b8868f1805ee6b0bdea495bbc89f5e5784dd0db Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 6 Aug 2022 01:09:51 +0200 Subject: [PATCH] Add delete option for votes, add "not voted" votes for later added dates --- clubhaus/homepage/admin.py | 3 +- .../0018_eventdatevotes_available.py | 19 ++++++++ clubhaus/homepage/models.py | 3 +- .../homepage/templates/homepage/events.html | 43 +++++++++++++------ clubhaus/homepage/views.py | 43 ++++++++++++------- 5 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 clubhaus/homepage/migrations/0018_eventdatevotes_available.py diff --git a/clubhaus/homepage/admin.py b/clubhaus/homepage/admin.py index d85d353..4a4c645 100644 --- a/clubhaus/homepage/admin.py +++ b/clubhaus/homepage/admin.py @@ -31,7 +31,8 @@ class VotingUserAdmin(admin.ModelAdmin): @admin.register(EventDateVotes) class EventDateVotesAdmin(admin.ModelAdmin): - list_display = ("id", "voter", "date") + list_display = ("id", "voter", "date", "available") + list_editable = ('available',) ordering = ("id",) diff --git a/clubhaus/homepage/migrations/0018_eventdatevotes_available.py b/clubhaus/homepage/migrations/0018_eventdatevotes_available.py new file mode 100644 index 0000000..0b09d4a --- /dev/null +++ b/clubhaus/homepage/migrations/0018_eventdatevotes_available.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0.5 on 2022-08-05 21:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0017_remove_eventdatevotes_available'), + ] + + operations = [ + migrations.AddField( + model_name='eventdatevotes', + name='available', + field=models.BooleanField(default=True), + preserve_default=False, + ), + ] diff --git a/clubhaus/homepage/models.py b/clubhaus/homepage/models.py index 9c2903c..bed190b 100644 --- a/clubhaus/homepage/models.py +++ b/clubhaus/homepage/models.py @@ -45,6 +45,7 @@ class ClubhausEvent(models.Model): class EventDateVotes(models.Model): voter = models.ForeignKey(to="VotingUser", on_delete=models.CASCADE) date = models.ForeignKey(to="EventDate", to_field="date", on_delete=models.CASCADE) + available = models.BooleanField() class Meta: constraints = [ @@ -65,4 +66,4 @@ class VotingUser(models.Model): ] def __str__(self): - return f"{self.name}({self.id})" + return f"{self.name} ({self.id})" diff --git a/clubhaus/homepage/templates/homepage/events.html b/clubhaus/homepage/templates/homepage/events.html index f10d134..d9136be 100644 --- a/clubhaus/homepage/templates/homepage/events.html +++ b/clubhaus/homepage/templates/homepage/events.html @@ -28,6 +28,15 @@ new Date("{{ next_event.date.isoformat }}"), countdown.DAYS | countdown.HOURS | countdown.MINUTES | countdown.SECONDS); + {% endblock %} {% block main %} @@ -61,7 +70,8 @@
@@ -103,10 +113,12 @@ {{ voter.0.name }} {% for date in voter.1.items %} - {% if date.1 %} + {% if date.1 == True %} - {% else %} + {% elif date.1 == False %} + {% else %} + {% endif %} {% endfor %} @@ -167,14 +179,15 @@ aria-hidden="true">