diff --git a/src/events/admin.py b/src/events/admin.py index 77ae37b..9c943eb 100644 --- a/src/events/admin.py +++ b/src/events/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import Event, Scores +from .models import Event, Scores, EventPlayer, Team #admin.site.register(Event) #admin.site.register(Scores) @@ -21,3 +21,21 @@ class score(admin.ModelAdmin): search_fields = ['user__username', 'score', 'event__name'] # Register your models here. + +@admin.register(Team) +class team(admin.ModelAdmin): + #list display + list_display = ['name', 'password'] + #list Filter + # list_filter = ('event',) + # search list + search_fields = ['name'] + +@admin.register(EventPlayer) +class eventplayer(admin.ModelAdmin): + #list display + list_display = ['user', 'event', 'team'] + #list Filter + list_filter = ('event', 'team__name') + # search list + search_fields = ['user__username', 'event__name'] \ No newline at end of file diff --git a/src/events/forms.py b/src/events/forms.py index acdc47e..108700d 100644 --- a/src/events/forms.py +++ b/src/events/forms.py @@ -1,4 +1,11 @@ from django import forms +from .models import Team class submit_flag(forms.Form): flag = forms.CharField(label="Flag", max_length=100) + +class create_team(forms.ModelForm): + password = forms.CharField(widget=forms.PasswordInput()) + class Meta(): + model = Team + fields = ('name','password') \ No newline at end of file diff --git a/src/events/migrations/0004_auto_20211215_2105.py b/src/events/migrations/0004_auto_20211215_2105.py new file mode 100644 index 0000000..76b77fa --- /dev/null +++ b/src/events/migrations/0004_auto_20211215_2105.py @@ -0,0 +1,42 @@ +# Generated by Django 3.1.5 on 2021-12-15 21:05 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('events', '0003_auto_20211019_1519'), + ] + + operations = [ + migrations.CreateModel( + name='Team', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('password', models.CharField(max_length=200)), + ('size', models.PositiveIntegerField(default=1)), + ('score', models.PositiveIntegerField(db_index=True, default=0)), + ('last_submission_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Last Submission Date')), + ], + ), + migrations.AlterField( + model_name='scores', + name='id', + field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.CreateModel( + name='EventPlayer', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.event')), + ('team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.team')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/src/events/migrations/0005_auto_20211215_2124.py b/src/events/migrations/0005_auto_20211215_2124.py new file mode 100644 index 0000000..8c6d03b --- /dev/null +++ b/src/events/migrations/0005_auto_20211215_2124.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.5 on 2021-12-15 21:24 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0004_auto_20211215_2105'), + ] + + operations = [ + migrations.AlterField( + model_name='eventplayer', + name='team', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='events.team'), + ), + ] diff --git a/src/events/migrations/0006_team_event.py b/src/events/migrations/0006_team_event.py new file mode 100644 index 0000000..fde2f2b --- /dev/null +++ b/src/events/migrations/0006_team_event.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.5 on 2021-12-15 22:16 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0005_auto_20211215_2124'), + ] + + operations = [ + migrations.AddField( + model_name='team', + name='event', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='events.event'), + ), + ] diff --git a/src/events/models.py b/src/events/models.py index ea8edea..7abf92c 100644 --- a/src/events/models.py +++ b/src/events/models.py @@ -23,4 +23,22 @@ class Scores(models.Model): score = models.PositiveIntegerField(default=0, db_index=True) last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now) class Meta: - ordering = ['-score', 'last_submission_date', 'user__username'] \ No newline at end of file + ordering = ['-score', 'last_submission_date', 'user__username'] + +class Team(models.Model): + name = models.CharField(max_length=200) + password = models.CharField(max_length=200) + event = models.ForeignKey(Event, on_delete=models.CASCADE, null=True) + size = models.PositiveIntegerField(default=1) + score = models.PositiveIntegerField(default=0, db_index=True) + last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now) + def __str__(self): + return self.name + +class EventPlayer(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE) + event = models.ForeignKey(Event, on_delete=models.CASCADE) + # score = models.PositiveIntegerField(default=0, db_index=True) + # last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now) + team = models.ForeignKey(Team, on_delete=models.CASCADE, null=True) + diff --git a/src/events/templates/events/create_team.html b/src/events/templates/events/create_team.html new file mode 100644 index 0000000..e62920b --- /dev/null +++ b/src/events/templates/events/create_team.html @@ -0,0 +1,60 @@ +{% extends 'base.html' %} +{% block content %} +{% load i18n %} +