Files
boxofficefantasy/draft/models.py
Anthony Correa cd4d974fce Add timed bidding support with countdown displays and debug view
- Added `bidding_duration` field to `DraftSessionSettings` model and migration.
- Updated `DraftStateManager` to manage bidding start/end times using session settings.
- Extended WebSocket payloads to include bidding timer data.
- Added `DraftCountdownClock` React component and integrated into admin and participant UIs.
- Created new `DraftDebug` view, template, and front-end component for real-time state debugging.
- Updated utility functions to handle new timer fields in draft state.
- Changed script tags in templates to load with `defer` for non-blocking execution.
2025-08-10 18:19:54 -05:00

72 lines
2.0 KiB
Python

from django.db.models import (
ForeignKey,
Model,
IntegerField,
BooleanField,
CASCADE,
PROTECT,
OneToOneField,
ManyToManyField,
)
from boxofficefantasy.models import Season, User, Movie
from boxofficefantasy_project.utils import encode_id, decode_id
# Create your models here.
class DraftSession(Model):
season = ForeignKey(Season, on_delete=CASCADE)
participants: ManyToManyField = ManyToManyField(
User, through="DraftSessionParticipant", related_name="participant_entries"
)
movies: ManyToManyField = ManyToManyField(Movie, related_name="draft_sessions", blank=True)
@property
def hashid(self):
if not self.pk:
return ""
return f"{encode_id(self.pk)}"
@classmethod
def decode_id(cls, hashed_id: str) -> id:
return decode_id(hashed_id)
def save(self, *args, **kwargs):
is_new = self.pk is None
super().save(*args, **kwargs)
if is_new and not hasattr(self, "settings"):
DraftSessionSettings.objects.create(draft_session=self)
class DraftSessionParticipant(Model):
draft_session = ForeignKey(DraftSession, on_delete=CASCADE, blank=True)
user = ForeignKey(User, on_delete=CASCADE)
class Meta:
unique_together = [("draft_session", "user")]
def __str__(self):
return f"{self.user} in {self.draft_session}"
class DraftPick(Model):
draft = ForeignKey(DraftSession, on_delete=CASCADE, related_name="draft_picks")
movie = ForeignKey(Movie, on_delete=CASCADE)
winner = ForeignKey(User, on_delete=CASCADE)
bid_amount = IntegerField()
nomination_order = IntegerField()
class DraftSessionSettings(Model):
starting_budget = IntegerField(default=100)
draft_session = OneToOneField(
DraftSession, on_delete=CASCADE, related_name="settings"
)
bidding_duration = IntegerField(default=90)
def __str__(self):
return f"Settings for {self.draft_session}"
class Meta:
verbose_name_plural = "Draft session settings"