website/src/events/models.py

41 lines
1.8 KiB
Python
Raw Normal View History

from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import timezone
import uuid
# Create your models here.
class Event(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=200)
logo = models.CharField(max_length=200)
img = models.CharField(max_length=200)
description = models.TextField()
start_date = models.DateTimeField()
end_date = models.DateTimeField()
password = models.CharField(max_length=200, blank=True)
slug = models.SlugField(max_length=55)
team_size = models.PositiveIntegerField(default=1)
def __str__(self):
return self.name
2021-12-17 19:02:19 +01:00
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)
score = models.PositiveIntegerField(default=0, db_index=True)
last_submission_date = models.DateTimeField('Last Submission Date', default=timezone.now)
2022-01-15 00:44:25 +01:00
auto = models.BooleanField(default=False)
2021-12-17 19:02:19 +01:00
def __str__(self):
return self.name
class EventPlayer(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
2021-12-17 19:02:19 +01:00
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)
2021-12-17 19:02:19 +01:00
team = models.ForeignKey(Team, on_delete=models.CASCADE, null=True)
class Meta:
ordering = ['-score', 'last_submission_date', 'user__username']
2021-12-17 19:02:19 +01:00