Remove django-auto-prefetch

This commit is contained in:
2025-05-01 02:47:09 +02:00
parent d7b31e1d42
commit 73f1870431
4 changed files with 29 additions and 108 deletions

View File

@ -3,7 +3,6 @@ from __future__ import annotations
import logging
from typing import ClassVar
import auto_prefetch
from django.contrib.auth.models import AbstractUser
from django.db import models
@ -21,7 +20,7 @@ class User(AbstractUser):
return self.username
class ScrapedJson(auto_prefetch.Model):
class ScrapedJson(models.Model):
"""The JSON data from the Twitch API.
This data is from https://github.com/TheLovinator1/TwitchDropsMiner.
@ -32,7 +31,7 @@ class ScrapedJson(auto_prefetch.Model):
modified_at = models.DateTimeField(auto_now=True)
imported_at = models.DateTimeField(null=True)
class Meta(auto_prefetch.Model.Meta):
class Meta:
ordering: ClassVar[list[str]] = ["-created_at"]
def __str__(self) -> str:
@ -40,7 +39,7 @@ class ScrapedJson(auto_prefetch.Model):
return f"{'' if self.imported_at else 'Not imported - '}{self.created_at}"
class Organization(auto_prefetch.Model):
class Organization(models.Model):
"""Represents the owner/organization of a Drop Campaign."""
org_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the owner.")
@ -49,7 +48,7 @@ class Organization(auto_prefetch.Model):
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
class Meta(auto_prefetch.Model.Meta):
class Meta:
ordering: ClassVar[list[str]] = ["name"]
def __str__(self) -> str:
@ -57,7 +56,7 @@ class Organization(auto_prefetch.Model):
return f"{self.name or self.org_id} - {self.created_at}"
class Game(auto_prefetch.Model):
class Game(models.Model):
"""The game the drop campaign is for. Note that some reward campaigns are not tied to a game."""
game_id = models.TextField(primary_key=True, help_text="The Twitch ID of the game.")
@ -69,7 +68,7 @@ class Game(auto_prefetch.Model):
created_at = models.DateTimeField(auto_now_add=True, help_text="When the game was first added to the database.")
modified_at = models.DateTimeField(auto_now=True, help_text="When the game was last modified.")
class Meta(auto_prefetch.Model.Meta):
class Meta:
ordering: ClassVar[list[str]] = ["display_name"]
def __str__(self) -> str:
@ -77,7 +76,7 @@ class Game(auto_prefetch.Model):
return f"{self.display_name or self.game_id} - {self.created_at}"
class DropCampaign(auto_prefetch.Model):
class DropCampaign(models.Model):
"""This is the drop campaign we will see on the front end."""
campaign_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the drop campaign.")
@ -89,14 +88,14 @@ class DropCampaign(auto_prefetch.Model):
image_url = models.URLField(blank=True, help_text="The URL to the image for the drop campaign.")
name = models.TextField(blank=True, help_text="The name of the drop campaign.")
status = models.TextField(blank=True, help_text="The status of the drop campaign.")
game = auto_prefetch.ForeignKey(
game = models.ForeignKey(
to=Game,
help_text="The game associated with this campaign",
null=True,
on_delete=models.SET_NULL,
related_name="drop_campaigns",
)
owner = auto_prefetch.ForeignKey(
owner = models.ForeignKey(
Organization,
help_text="The organization running this campaign",
null=True,
@ -110,7 +109,7 @@ class DropCampaign(auto_prefetch.Model):
)
modified_at = models.DateTimeField(auto_now=True, help_text="When the drop campaign was last modified.")
class Meta(auto_prefetch.Model.Meta):
class Meta:
ordering: ClassVar[list[str]] = ["end_at"]
def __str__(self) -> str:
@ -118,7 +117,7 @@ class DropCampaign(auto_prefetch.Model):
return f"{self.name or self.campaign_id} - {self.created_at}"
class Benefit(auto_prefetch.Model):
class Benefit(models.Model):
"""Represents a specific reward/benefit within a Drop."""
benefit_id = models.TextField(primary_key=True, unique=True, help_text="Twitch's unique ID for the benefit")
@ -130,8 +129,8 @@ class Benefit(auto_prefetch.Model):
image_asset_url = models.URLField(blank=True, help_text="The URL to the image for the benefit.")
is_ios_available = models.BooleanField(null=True, help_text="If the benefit is farmable on iOS.")
name = models.TextField(blank=True, help_text="Name of the benefit/reward")
game = auto_prefetch.ForeignKey(Game, on_delete=models.SET_NULL, related_name="benefits", null=True)
owner_organization = auto_prefetch.ForeignKey(
game = models.ForeignKey(Game, on_delete=models.SET_NULL, related_name="benefits", null=True)
owner_organization = models.ForeignKey(
Organization,
on_delete=models.SET_NULL,
related_name="benefits",
@ -142,7 +141,7 @@ class Benefit(auto_prefetch.Model):
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
class Meta(auto_prefetch.Model.Meta):
class Meta:
ordering: ClassVar[list[str]] = ["-twitch_created_at"]
def __str__(self) -> str:
@ -150,7 +149,7 @@ class Benefit(auto_prefetch.Model):
return f"{self.name or self.benefit_id} - {self.twitch_created_at}"
class TimeBasedDrop(auto_prefetch.Model):
class TimeBasedDrop(models.Model):
"""Represents a time-based drop within a Campaign."""
drop_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the drop.")
@ -164,7 +163,7 @@ class TimeBasedDrop(auto_prefetch.Model):
start_at = models.DateTimeField(help_text="Drop start time")
end_at = models.DateTimeField(help_text="Drop end time")
campaign = auto_prefetch.ForeignKey(
campaign = models.ForeignKey(
DropCampaign,
help_text="The campaign this drop belongs to",
on_delete=models.CASCADE,
@ -179,7 +178,7 @@ class TimeBasedDrop(auto_prefetch.Model):
created_at = models.DateTimeField(auto_now_add=True, help_text="When the drop was first added to the database.")
modified_at = models.DateTimeField(auto_now=True, help_text="When the drop was last modified.")
class Meta(auto_prefetch.Model.Meta):
class Meta:
ordering: ClassVar[list[str]] = ["required_minutes_watched"]
def __str__(self) -> str: