Add WIP
This commit is contained in:
@ -3,10 +3,7 @@ from typing import Literal
|
||||
import auto_prefetch
|
||||
from django.db import models
|
||||
from django.db.models import Value
|
||||
from django.db.models.functions import (
|
||||
Concat,
|
||||
)
|
||||
from simple_history.models import HistoricalRecords
|
||||
from django.db.models.functions import Concat
|
||||
|
||||
|
||||
class Organization(auto_prefetch.Model):
|
||||
@ -35,6 +32,11 @@ class Game(auto_prefetch.Model):
|
||||
For example, MultiVersus.
|
||||
"""
|
||||
|
||||
organization = auto_prefetch.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="games",
|
||||
)
|
||||
id = models.TextField(primary_key=True)
|
||||
slug = models.TextField(blank=True, null=True)
|
||||
twitch_url = models.GeneratedField( # type: ignore # noqa: PGH003
|
||||
@ -54,7 +56,6 @@ class Game(auto_prefetch.Model):
|
||||
display_name = models.TextField(blank=True, null=True)
|
||||
added_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
|
||||
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||
history = HistoricalRecords()
|
||||
|
||||
class Meta(auto_prefetch.Model.Meta):
|
||||
verbose_name: str = "Game"
|
||||
@ -65,55 +66,29 @@ class Game(auto_prefetch.Model):
|
||||
return self.display_name or self.slug or self.id
|
||||
|
||||
|
||||
class DropBenefit(auto_prefetch.Model):
|
||||
"""Information about the drop."""
|
||||
class Drop(auto_prefetch.Model):
|
||||
"""The actual drop that is being given out."""
|
||||
|
||||
id = models.TextField(primary_key=True)
|
||||
created_at = models.DateTimeField(blank=True, null=True)
|
||||
entitlement_limit = models.IntegerField(blank=True, null=True)
|
||||
image_asset_url = models.URLField(blank=True, null=True)
|
||||
is_ios_available = models.BooleanField(blank=True, null=True)
|
||||
name = models.TextField(blank=True, null=True)
|
||||
owner_organization = auto_prefetch.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="drop_benefits",
|
||||
)
|
||||
game = auto_prefetch.ForeignKey(Game, on_delete=models.CASCADE, related_name="drop_benefits")
|
||||
added_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
|
||||
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||
history = HistoricalRecords()
|
||||
|
||||
class Meta(auto_prefetch.Model.Meta):
|
||||
verbose_name: str = "Drop Benefit"
|
||||
verbose_name_plural: str = "Drop Benefits"
|
||||
ordering: tuple[Literal["name"]] = ("name",)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.owner_organization.name} - {self.game.display_name} - {self.name}"
|
||||
|
||||
|
||||
class TimeBasedDrop(auto_prefetch.Model):
|
||||
"""The actual drop that is being given out."""
|
||||
|
||||
id = models.TextField(primary_key=True)
|
||||
required_subs = models.IntegerField(blank=True, null=True)
|
||||
end_at = models.DateTimeField(blank=True, null=True)
|
||||
name = models.TextField(blank=True, null=True)
|
||||
required_minutes_watched = models.IntegerField(blank=True, null=True)
|
||||
start_at = models.DateTimeField(blank=True, null=True)
|
||||
benefits = models.ManyToManyField(DropBenefit, related_name="time_based_drops")
|
||||
added_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
|
||||
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||
history = HistoricalRecords()
|
||||
drop_campaign = auto_prefetch.ForeignKey("DropCampaign", on_delete=models.CASCADE, related_name="drops")
|
||||
|
||||
class Meta(auto_prefetch.Model.Meta):
|
||||
verbose_name: str = "Time-Based Drop"
|
||||
verbose_name_plural: str = "Time-Based Drops"
|
||||
verbose_name: str = "Drop"
|
||||
verbose_name_plural: str = "Drops"
|
||||
ordering: tuple[Literal["name"]] = ("name",)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.benefits.first()} - {self.name}"
|
||||
return f"{self.name}"
|
||||
|
||||
|
||||
class DropCampaign(auto_prefetch.Model):
|
||||
@ -136,15 +111,8 @@ class DropCampaign(auto_prefetch.Model):
|
||||
on_delete=models.CASCADE,
|
||||
related_name="drop_campaigns",
|
||||
)
|
||||
owner = auto_prefetch.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="drop_campaigns",
|
||||
)
|
||||
time_based_drops = models.ManyToManyField(TimeBasedDrop, related_name="drop_campaigns")
|
||||
added_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
|
||||
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||
history = HistoricalRecords()
|
||||
|
||||
class Meta(auto_prefetch.Model.Meta):
|
||||
verbose_name: str = "Drop Campaign"
|
||||
@ -152,4 +120,4 @@ class DropCampaign(auto_prefetch.Model):
|
||||
ordering: tuple[Literal["name"]] = ("name",)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.owner.name} - {self.game.display_name} - {self.name}"
|
||||
return f"{self.game.display_name} - {self.name}"
|
||||
|
Reference in New Issue
Block a user