Use django-auto-prefetch
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
discord-webhook
|
discord-webhook
|
||||||
django-allauth[socialaccount]
|
django-allauth[socialaccount]
|
||||||
|
django-auto-prefetch
|
||||||
django-ninja
|
django-ninja
|
||||||
django-simple-history
|
django-simple-history
|
||||||
django>=0.0.0.dev0
|
django>=0.0.0.dev0
|
||||||
|
@ -0,0 +1,171 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-07-01 15:44
|
||||||
|
|
||||||
|
import auto_prefetch
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.db.models.manager
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("twitch_app", "0005_alter_dropbenefit_options_alter_dropcampaign_options_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="dropbenefit",
|
||||||
|
options={
|
||||||
|
"base_manager_name": "prefetch_manager",
|
||||||
|
"ordering": ("name",),
|
||||||
|
"verbose_name": "Drop Benefit",
|
||||||
|
"verbose_name_plural": "Drop Benefits",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="dropcampaign",
|
||||||
|
options={
|
||||||
|
"base_manager_name": "prefetch_manager",
|
||||||
|
"ordering": ("name",),
|
||||||
|
"verbose_name": "Drop Campaign",
|
||||||
|
"verbose_name_plural": "Drop Campaigns",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="game",
|
||||||
|
options={
|
||||||
|
"base_manager_name": "prefetch_manager",
|
||||||
|
"ordering": ("display_name",),
|
||||||
|
"verbose_name": "Game",
|
||||||
|
"verbose_name_plural": "Games",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="organization",
|
||||||
|
options={
|
||||||
|
"base_manager_name": "prefetch_manager",
|
||||||
|
"ordering": ("name",),
|
||||||
|
"verbose_name": "Organization",
|
||||||
|
"verbose_name_plural": "Organizations",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="timebaseddrop",
|
||||||
|
options={
|
||||||
|
"base_manager_name": "prefetch_manager",
|
||||||
|
"ordering": ("name",),
|
||||||
|
"verbose_name": "Time-Based Drop",
|
||||||
|
"verbose_name_plural": "Time-Based Drops",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AlterModelManagers(
|
||||||
|
name="dropbenefit",
|
||||||
|
managers=[
|
||||||
|
("objects", django.db.models.manager.Manager()),
|
||||||
|
("prefetch_manager", django.db.models.manager.Manager()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterModelManagers(
|
||||||
|
name="dropcampaign",
|
||||||
|
managers=[
|
||||||
|
("objects", django.db.models.manager.Manager()),
|
||||||
|
("prefetch_manager", django.db.models.manager.Manager()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterModelManagers(
|
||||||
|
name="game",
|
||||||
|
managers=[
|
||||||
|
("objects", django.db.models.manager.Manager()),
|
||||||
|
("prefetch_manager", django.db.models.manager.Manager()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterModelManagers(
|
||||||
|
name="organization",
|
||||||
|
managers=[
|
||||||
|
("objects", django.db.models.manager.Manager()),
|
||||||
|
("prefetch_manager", django.db.models.manager.Manager()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterModelManagers(
|
||||||
|
name="timebaseddrop",
|
||||||
|
managers=[
|
||||||
|
("objects", django.db.models.manager.Manager()),
|
||||||
|
("prefetch_manager", django.db.models.manager.Manager()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="dropbenefit",
|
||||||
|
name="game",
|
||||||
|
field=auto_prefetch.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="twitch_app.game"),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="dropbenefit",
|
||||||
|
name="owner_organization",
|
||||||
|
field=auto_prefetch.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="twitch_app.organization"),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="dropcampaign",
|
||||||
|
name="game",
|
||||||
|
field=auto_prefetch.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="drop_campaigns",
|
||||||
|
to="twitch_app.game",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="dropcampaign",
|
||||||
|
name="owner",
|
||||||
|
field=auto_prefetch.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="drop_campaigns",
|
||||||
|
to="twitch_app.organization",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="historicaldropbenefit",
|
||||||
|
name="game",
|
||||||
|
field=auto_prefetch.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
db_constraint=False,
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.DO_NOTHING,
|
||||||
|
related_name="+",
|
||||||
|
to="twitch_app.game",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="historicaldropbenefit",
|
||||||
|
name="owner_organization",
|
||||||
|
field=auto_prefetch.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
db_constraint=False,
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.DO_NOTHING,
|
||||||
|
related_name="+",
|
||||||
|
to="twitch_app.organization",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="historicaldropcampaign",
|
||||||
|
name="game",
|
||||||
|
field=auto_prefetch.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
db_constraint=False,
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.DO_NOTHING,
|
||||||
|
related_name="+",
|
||||||
|
to="twitch_app.game",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="historicaldropcampaign",
|
||||||
|
name="owner",
|
||||||
|
field=auto_prefetch.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
db_constraint=False,
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.DO_NOTHING,
|
||||||
|
related_name="+",
|
||||||
|
to="twitch_app.organization",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -1,3 +1,4 @@
|
|||||||
|
import auto_prefetch
|
||||||
from django.contrib.humanize.templatetags.humanize import naturaltime
|
from django.contrib.humanize.templatetags.humanize import naturaltime
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Value
|
from django.db.models import Value
|
||||||
@ -8,13 +9,13 @@ from django.utils import timezone
|
|||||||
from simple_history.models import HistoricalRecords
|
from simple_history.models import HistoricalRecords
|
||||||
|
|
||||||
|
|
||||||
class Organization(models.Model):
|
class Organization(auto_prefetch.Model):
|
||||||
id = models.TextField(primary_key=True)
|
id = models.TextField(primary_key=True)
|
||||||
name = models.TextField(blank=True, null=True)
|
name = models.TextField(blank=True, null=True)
|
||||||
added_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
|
added_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
|
||||||
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta(auto_prefetch.Model.Meta):
|
||||||
verbose_name = "Organization"
|
verbose_name = "Organization"
|
||||||
verbose_name_plural = "Organizations"
|
verbose_name_plural = "Organizations"
|
||||||
ordering = ("name",)
|
ordering = ("name",)
|
||||||
@ -23,7 +24,7 @@ class Organization(models.Model):
|
|||||||
return self.name or self.id
|
return self.name or self.id
|
||||||
|
|
||||||
|
|
||||||
class Game(models.Model):
|
class Game(auto_prefetch.Model):
|
||||||
id = models.TextField(primary_key=True)
|
id = models.TextField(primary_key=True)
|
||||||
slug = models.TextField(blank=True, null=True)
|
slug = models.TextField(blank=True, null=True)
|
||||||
twitch_url = models.GeneratedField( # type: ignore # noqa: PGH003
|
twitch_url = models.GeneratedField( # type: ignore # noqa: PGH003
|
||||||
@ -45,7 +46,7 @@ class Game(models.Model):
|
|||||||
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||||
history = HistoricalRecords()
|
history = HistoricalRecords()
|
||||||
|
|
||||||
class Meta:
|
class Meta(auto_prefetch.Model.Meta):
|
||||||
verbose_name = "Game"
|
verbose_name = "Game"
|
||||||
verbose_name_plural = "Games"
|
verbose_name_plural = "Games"
|
||||||
ordering = ("display_name",)
|
ordering = ("display_name",)
|
||||||
@ -54,20 +55,23 @@ class Game(models.Model):
|
|||||||
return self.display_name or self.slug or self.id
|
return self.display_name or self.slug or self.id
|
||||||
|
|
||||||
|
|
||||||
class DropBenefit(models.Model):
|
class DropBenefit(auto_prefetch.Model):
|
||||||
id = models.TextField(primary_key=True)
|
id = models.TextField(primary_key=True)
|
||||||
created_at = models.DateTimeField(blank=True, null=True)
|
created_at = models.DateTimeField(blank=True, null=True)
|
||||||
entitlement_limit = models.IntegerField(blank=True, null=True)
|
entitlement_limit = models.IntegerField(blank=True, null=True)
|
||||||
image_asset_url = models.URLField(blank=True, null=True)
|
image_asset_url = models.URLField(blank=True, null=True)
|
||||||
is_ios_available = models.BooleanField(blank=True, null=True)
|
is_ios_available = models.BooleanField(blank=True, null=True)
|
||||||
name = models.TextField(blank=True, null=True)
|
name = models.TextField(blank=True, null=True)
|
||||||
owner_organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
|
owner_organization = auto_prefetch.ForeignKey(
|
||||||
game = models.ForeignKey(Game, on_delete=models.CASCADE)
|
Organization,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
game = auto_prefetch.ForeignKey(Game, on_delete=models.CASCADE)
|
||||||
added_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
|
added_at = models.DateTimeField(blank=True, null=True, auto_now_add=True)
|
||||||
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||||
history = HistoricalRecords()
|
history = HistoricalRecords()
|
||||||
|
|
||||||
class Meta:
|
class Meta(auto_prefetch.Model.Meta):
|
||||||
verbose_name = "Drop Benefit"
|
verbose_name = "Drop Benefit"
|
||||||
verbose_name_plural = "Drop Benefits"
|
verbose_name_plural = "Drop Benefits"
|
||||||
ordering = ("name",)
|
ordering = ("name",)
|
||||||
@ -76,7 +80,7 @@ class DropBenefit(models.Model):
|
|||||||
return f"{self.owner_organization.name} - {self.game.display_name} - {self.name}"
|
return f"{self.owner_organization.name} - {self.game.display_name} - {self.name}"
|
||||||
|
|
||||||
|
|
||||||
class TimeBasedDrop(models.Model):
|
class TimeBasedDrop(auto_prefetch.Model):
|
||||||
id = models.TextField(primary_key=True)
|
id = models.TextField(primary_key=True)
|
||||||
required_subs = models.IntegerField(blank=True, null=True)
|
required_subs = models.IntegerField(blank=True, null=True)
|
||||||
end_at = models.DateTimeField(blank=True, null=True)
|
end_at = models.DateTimeField(blank=True, null=True)
|
||||||
@ -88,7 +92,7 @@ class TimeBasedDrop(models.Model):
|
|||||||
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||||
history = HistoricalRecords()
|
history = HistoricalRecords()
|
||||||
|
|
||||||
class Meta:
|
class Meta(auto_prefetch.Model.Meta):
|
||||||
verbose_name = "Time-Based Drop"
|
verbose_name = "Time-Based Drop"
|
||||||
verbose_name_plural = "Time-Based Drops"
|
verbose_name_plural = "Time-Based Drops"
|
||||||
ordering = ("name",)
|
ordering = ("name",)
|
||||||
@ -101,7 +105,7 @@ class TimeBasedDrop(models.Model):
|
|||||||
return f"{self.benefits.first()} - {self.name}"
|
return f"{self.benefits.first()} - {self.name}"
|
||||||
|
|
||||||
|
|
||||||
class DropCampaign(models.Model):
|
class DropCampaign(auto_prefetch.Model):
|
||||||
id = models.TextField(primary_key=True)
|
id = models.TextField(primary_key=True)
|
||||||
account_link_url = models.URLField(blank=True, null=True)
|
account_link_url = models.URLField(blank=True, null=True)
|
||||||
description = models.TextField(blank=True, null=True)
|
description = models.TextField(blank=True, null=True)
|
||||||
@ -111,12 +115,12 @@ class DropCampaign(models.Model):
|
|||||||
name = models.TextField(blank=True, null=True)
|
name = models.TextField(blank=True, null=True)
|
||||||
start_at = models.DateTimeField(blank=True, null=True)
|
start_at = models.DateTimeField(blank=True, null=True)
|
||||||
status = models.TextField(blank=True, null=True)
|
status = models.TextField(blank=True, null=True)
|
||||||
game = models.ForeignKey(
|
game = auto_prefetch.ForeignKey(
|
||||||
Game,
|
Game,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name="drop_campaigns",
|
related_name="drop_campaigns",
|
||||||
)
|
)
|
||||||
owner = models.ForeignKey(
|
owner = auto_prefetch.ForeignKey(
|
||||||
Organization,
|
Organization,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name="drop_campaigns",
|
related_name="drop_campaigns",
|
||||||
@ -126,7 +130,7 @@ class DropCampaign(models.Model):
|
|||||||
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
modified_at = models.DateTimeField(blank=True, null=True, auto_now=True)
|
||||||
history = HistoricalRecords()
|
history = HistoricalRecords()
|
||||||
|
|
||||||
class Meta:
|
class Meta(auto_prefetch.Model.Meta):
|
||||||
verbose_name = "Drop Campaign"
|
verbose_name = "Drop Campaign"
|
||||||
verbose_name_plural = "Drop Campaigns"
|
verbose_name_plural = "Drop Campaigns"
|
||||||
ordering = ("name",)
|
ordering = ("name",)
|
||||||
|
Reference in New Issue
Block a user