diff --git a/clubhaus/homepage/admin.py b/clubhaus/homepage/admin.py index ac4ad5f..d85d353 100644 --- a/clubhaus/homepage/admin.py +++ b/clubhaus/homepage/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin # Register your models here. -from .models import Tobacco, TobaccoCategory, ClubhausEvent, EventDate, EventDateVotes +from .models import Tobacco, TobaccoCategory, ClubhausEvent, EventDate, EventDateVotes, VotingUser @admin.register(Tobacco) @@ -23,9 +23,15 @@ class EventDateAdmin(admin.ModelAdmin): ordering = ("id",) +@admin.register(VotingUser) +class VotingUserAdmin(admin.ModelAdmin): + list_display = ("id", "name", "modify_key") + ordering = ("id",) + + @admin.register(EventDateVotes) class EventDateVotesAdmin(admin.ModelAdmin): - list_display = ("id", "name", "date") + list_display = ("id", "voter", "date") ordering = ("id",) diff --git a/clubhaus/homepage/migrations/0011_eventdatevotes_modify_key.py b/clubhaus/homepage/migrations/0011_eventdatevotes_modify_key.py new file mode 100644 index 0000000..2232e03 --- /dev/null +++ b/clubhaus/homepage/migrations/0011_eventdatevotes_modify_key.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0.5 on 2022-08-02 22:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0010_alter_eventdatevotes_unique_together_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='eventdatevotes', + name='modify_key', + field=models.TextField(default=''), + preserve_default=False, + ), + ] diff --git a/clubhaus/homepage/migrations/0012_votinguser_remove_eventdatevotes_unique_name_date_and_more.py b/clubhaus/homepage/migrations/0012_votinguser_remove_eventdatevotes_unique_name_date_and_more.py new file mode 100644 index 0000000..6d19545 --- /dev/null +++ b/clubhaus/homepage/migrations/0012_votinguser_remove_eventdatevotes_unique_name_date_and_more.py @@ -0,0 +1,41 @@ +# Generated by Django 4.0.5 on 2022-08-02 23:07 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0011_eventdatevotes_modify_key'), + ] + + operations = [ + migrations.CreateModel( + name='VotingUser', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + ), + migrations.RemoveConstraint( + model_name='eventdatevotes', + name='unique_name_date', + ), + migrations.RemoveField( + model_name='eventdatevotes', + name='modify_key', + ), + migrations.RemoveField( + model_name='eventdatevotes', + name='name', + ), + migrations.AddConstraint( + model_name='eventdatevotes', + constraint=models.UniqueConstraint(fields=('date',), name='unique_voter_day'), + ), + migrations.AddField( + model_name='eventdatevotes', + name='voter', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.votinguser'), + ), + ] diff --git a/clubhaus/homepage/migrations/0013_votinguser_modify_key_votinguser_name_and_more.py b/clubhaus/homepage/migrations/0013_votinguser_modify_key_votinguser_name_and_more.py new file mode 100644 index 0000000..502b64f --- /dev/null +++ b/clubhaus/homepage/migrations/0013_votinguser_modify_key_votinguser_name_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 4.0.5 on 2022-08-02 23:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0012_votinguser_remove_eventdatevotes_unique_name_date_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='votinguser', + name='modify_key', + field=models.CharField(default='', max_length=200), + preserve_default=False, + ), + migrations.AddField( + model_name='votinguser', + name='name', + field=models.CharField(default='', max_length=200), + preserve_default=False, + ), + migrations.AddConstraint( + model_name='votinguser', + constraint=models.UniqueConstraint(fields=('name', 'modify_key'), name='unique_name_modify_key'), + ), + ] diff --git a/clubhaus/homepage/migrations/0014_alter_eventdatevotes_voter.py b/clubhaus/homepage/migrations/0014_alter_eventdatevotes_voter.py new file mode 100644 index 0000000..38ee740 --- /dev/null +++ b/clubhaus/homepage/migrations/0014_alter_eventdatevotes_voter.py @@ -0,0 +1,20 @@ +# Generated by Django 4.0.5 on 2022-08-02 23:09 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0013_votinguser_modify_key_votinguser_name_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='eventdatevotes', + name='voter', + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.votinguser'), + preserve_default=False, + ), + ] diff --git a/clubhaus/homepage/migrations/0015_remove_eventdatevotes_unique_voter_day_and_more.py b/clubhaus/homepage/migrations/0015_remove_eventdatevotes_unique_voter_day_and_more.py new file mode 100644 index 0000000..7b63836 --- /dev/null +++ b/clubhaus/homepage/migrations/0015_remove_eventdatevotes_unique_voter_day_and_more.py @@ -0,0 +1,21 @@ +# Generated by Django 4.0.5 on 2022-08-02 23:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0014_alter_eventdatevotes_voter'), + ] + + operations = [ + migrations.RemoveConstraint( + model_name='eventdatevotes', + name='unique_voter_day', + ), + migrations.AddConstraint( + model_name='eventdatevotes', + constraint=models.UniqueConstraint(fields=('voter', 'date'), name='unique_voter_day'), + ), + ] diff --git a/clubhaus/homepage/migrations/0016_eventdatevotes_available.py b/clubhaus/homepage/migrations/0016_eventdatevotes_available.py new file mode 100644 index 0000000..9a028d7 --- /dev/null +++ b/clubhaus/homepage/migrations/0016_eventdatevotes_available.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0.5 on 2022-08-02 23:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0015_remove_eventdatevotes_unique_voter_day_and_more'), + ] + + 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 dd42838..b244311 100644 --- a/clubhaus/homepage/models.py +++ b/clubhaus/homepage/models.py @@ -43,13 +43,27 @@ class ClubhausEvent(models.Model): class EventDateVotes(models.Model): - name = models.CharField(max_length=200, blank=False) + voter = models.ForeignKey(to="VotingUser", on_delete=models.CASCADE) date = models.ForeignKey(to="EventDate", to_field="date", on_delete=models.CASCADE) + available = models.BooleanField(blank=False) class Meta: constraints = [ - models.UniqueConstraint(fields=("name", "date"), name="unique_name_date") + models.UniqueConstraint(fields=("voter", "date"), name="unique_voter_day") ] def __str__(self): - return f"{self.name} - {self.date.date.isoformat()}" + 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 = [ + models.UniqueConstraint(fields=("name", "modify_key"), name="unique_name_modify_key") + ] + + def __str__(self): + return f"{self.name}({self.id})" diff --git a/clubhaus/homepage/templates/homepage/events.html b/clubhaus/homepage/templates/homepage/events.html index 37eff4d..f46ee89 100644 --- a/clubhaus/homepage/templates/homepage/events.html +++ b/clubhaus/homepage/templates/homepage/events.html @@ -99,11 +99,12 @@
- {% for voter in votes.items %} + {% regroup votes by voter as voter_grouped %} + {% for indv_voter, indv_votes in voter_grouped %}