Files
boxofficefantasy/draft/models.py
Anthony Correa c9ce7a36d0 Integrate draft session support with phase handling and real-time updates
- Added user authentication UI in the base template for navbar.
- Expanded `league.dj.html` to include a new "Draft Sessions" tab showing active drafts.
- Refactored Django views and models to support `DraftSession` with participants and movies.
- Replaced deprecated models like `DraftParticipant` and `DraftMoviePool` with a new schema using `DraftSessionParticipant`.
- Introduced WebSocket consumers (`DraftAdminConsumer`, `DraftParticipantConsumer`) with structured phase logic and caching.
- Added `DraftStateManager` for managing draft state in Django cache.
- Created frontend UI components in React for draft admin and participants, including phase control and WebSocket message logging.
- Updated SCSS styles for improved UI structure and messaging area.
2025-08-02 08:56:41 -05:00

71 lines
1.9 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)
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"
)
def __str__(self):
return f"Settings for {self.draft_session}"
class Meta:
verbose_name_plural = "Draft session settings"