Files
Hulumath-Web/backend/toolbox/models.py
T

54 lines
1.6 KiB
Python

import uuid
from django.conf import settings
from django.db import models
class BoardSession(models.Model):
class Mode(models.TextChoices):
COLLABORATE = "collaborate", "协作展示"
DRAW_GUESS = "draw_guess", "数学你画我猜"
class Status(models.TextChoices):
WAITING = "waiting", "等待加入"
ACTIVE = "active", "进行中"
COMPLETED = "completed", "已完成"
CANCELLED = "cancelled", "已取消"
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
code = models.CharField(max_length=6, unique=True)
mode = models.CharField(
max_length=16,
choices=Mode.choices,
default=Mode.COLLABORATE,
)
host = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="hosted_board_sessions",
)
guest = models.ForeignKey(
settings.AUTH_USER_MODEL,
null=True,
blank=True,
on_delete=models.CASCADE,
related_name="joined_board_sessions",
)
target = models.CharField(max_length=40, blank=True)
host_score = models.PositiveSmallIntegerField(default=0)
guest_score = models.PositiveSmallIntegerField(default=0)
status = models.CharField(
max_length=16,
choices=Status.choices,
default=Status.WAITING,
)
expires_at = models.DateTimeField()
created_at = models.DateTimeField(auto_now_add=True)
completed_at = models.DateTimeField(null=True, blank=True)
class Meta:
ordering = ["-created_at"]
def __str__(self):
return f"{self.code} · {self.get_mode_display()}"