Improve admin page

This commit is contained in:
2024-07-01 17:41:51 +02:00
parent 219aee31af
commit 40587fa24f
11 changed files with 633 additions and 32 deletions

@ -1,6 +1,8 @@
from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from .models import DiscordSetting, Subscription
admin.site.register(DiscordSetting)
admin.site.register(Subscription)
# https://django-simple-history.readthedocs.io/en/latest/admin.html
admin.site.register(DiscordSetting, SimpleHistoryAdmin)
admin.site.register(Subscription, SimpleHistoryAdmin)

@ -0,0 +1,146 @@
# Generated by Django 5.0.6 on 2024-07-01 15:17
import django.db.models.deletion
import simple_history.models
from django.conf import settings
from django.db import migrations, models
from django.db.migrations.operations.base import Operation
class Migration(migrations.Migration):
dependencies: list[tuple[str, str]] = [
("core", "0003_subscription"),
("twitch_app", "0003_historicaldropbenefit_historicaldropcampaign_and_more"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations: list[Operation] = [
migrations.CreateModel(
name="HistoricalDiscordSetting",
fields=[
(
"id",
models.BigIntegerField(
auto_created=True,
blank=True,
db_index=True,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
("webhook_url", models.URLField()),
("disabled", models.BooleanField(default=False)),
("history_id", models.AutoField(primary_key=True, serialize=False)),
("history_date", models.DateTimeField(db_index=True)),
("history_change_reason", models.CharField(max_length=100, null=True)),
(
"history_type",
models.CharField(
choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")],
max_length=1,
),
),
(
"history_user",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"user",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "historical discord setting",
"verbose_name_plural": "historical discord settings",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name="HistoricalSubscription",
fields=[
(
"id",
models.BigIntegerField(
auto_created=True,
blank=True,
db_index=True,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(blank=True, editable=False)),
("history_id", models.AutoField(primary_key=True, serialize=False)),
("history_date", models.DateTimeField(db_index=True)),
("history_change_reason", models.CharField(max_length=100, null=True)),
(
"history_type",
models.CharField(
choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")],
max_length=1,
),
),
(
"discord_webhook",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="core.discordsetting",
),
),
(
"game",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="twitch_app.game",
),
),
(
"history_user",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"user",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "historical subscription",
"verbose_name_plural": "historical subscriptions",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]

@ -1,5 +1,6 @@
from django.contrib.auth.models import User
from django.db import models
from simple_history.models import HistoricalRecords
from twitch_app.models import Game
@ -8,6 +9,7 @@ class DiscordSetting(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
webhook_url = models.URLField()
history = HistoricalRecords()
disabled = models.BooleanField(default=False)
def __str__(self) -> str:
@ -18,6 +20,7 @@ class Subscription(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
game = models.ForeignKey(Game, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
history = HistoricalRecords()
discord_webhook = models.ForeignKey(DiscordSetting, on_delete=models.CASCADE)
def __str__(self) -> str: