Add timestamps for record creation and updates for all models
This commit is contained in:
parent
63f95a73db
commit
9b0f5153fc
3 changed files with 145 additions and 2 deletions
|
|
@ -11,6 +11,7 @@ class GameAdmin(admin.ModelAdmin):
|
|||
|
||||
list_display = ("id", "display_name", "slug")
|
||||
search_fields = ("id", "display_name", "slug")
|
||||
readonly_fields = ("added_at", "updated_at")
|
||||
|
||||
|
||||
@admin.register(Organization)
|
||||
|
|
@ -19,6 +20,7 @@ class OrganizationAdmin(admin.ModelAdmin):
|
|||
|
||||
list_display = ("id", "name")
|
||||
search_fields = ("id", "name")
|
||||
readonly_fields = ("added_at", "updated_at")
|
||||
|
||||
|
||||
class TimeBasedDropInline(admin.TabularInline):
|
||||
|
|
@ -36,7 +38,7 @@ class DropCampaignAdmin(admin.ModelAdmin):
|
|||
list_filter = ("game",)
|
||||
search_fields = ("id", "name", "description")
|
||||
inlines = [TimeBasedDropInline]
|
||||
readonly_fields = ("created_at", "updated_at")
|
||||
readonly_fields = ("added_at", "updated_at")
|
||||
|
||||
|
||||
class DropBenefitEdgeInline(admin.TabularInline):
|
||||
|
|
@ -60,6 +62,8 @@ class TimeBasedDropAdmin(admin.ModelAdmin):
|
|||
"end_at",
|
||||
)
|
||||
list_filter = ("campaign__game", "campaign")
|
||||
readonly_fields = ("added_at", "updated_at")
|
||||
|
||||
search_fields = ("id", "name")
|
||||
inlines = [DropBenefitEdgeInline]
|
||||
|
||||
|
|
@ -77,3 +81,4 @@ class DropBenefitAdmin(admin.ModelAdmin):
|
|||
)
|
||||
list_filter = ("distribution_type",)
|
||||
search_fields = ("id", "name")
|
||||
readonly_fields = ("added_at", "updated_at")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
# Generated by Django 5.2.5 on 2025-09-04 21:00
|
||||
|
||||
import django.utils.timezone
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('twitch', '0007_remove_game_unique_game_slug'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='dropcampaign',
|
||||
old_name='created_at',
|
||||
new_name='added_at',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='dropbenefit',
|
||||
name='added_at',
|
||||
field=models.DateTimeField(auto_now_add=True, db_index=True, default=django.utils.timezone.now, help_text='Timestamp when this benefit record was created.'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='dropbenefit',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True, help_text='Timestamp when this benefit record was last updated.'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='dropbenefitedge',
|
||||
name='added_at',
|
||||
field=models.DateTimeField(auto_now_add=True, db_index=True, default=django.utils.timezone.now, help_text='Timestamp when this drop-benefit edge was created.'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='dropbenefitedge',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True, help_text='Timestamp when this drop-benefit edge was last updated.'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='game',
|
||||
name='added_at',
|
||||
field=models.DateTimeField(auto_now_add=True, db_index=True, default=django.utils.timezone.now, help_text='Timestamp when this game record was created.'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='game',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True, help_text='Timestamp when this game record was last updated.'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='notificationsubscription',
|
||||
name='added_at',
|
||||
field=models.DateTimeField(auto_now_add=True, db_index=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='notificationsubscription',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='organization',
|
||||
name='added_at',
|
||||
field=models.DateTimeField(auto_now_add=True, db_index=True, default=django.utils.timezone.now, help_text='Timestamp when this organization record was created.'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='organization',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True, help_text='Timestamp when this organization record was last updated.'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='timebaseddrop',
|
||||
name='added_at',
|
||||
field=models.DateTimeField(auto_now_add=True, db_index=True, default=django.utils.timezone.now, help_text='Timestamp when this time-based drop record was created.'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='timebaseddrop',
|
||||
name='updated_at',
|
||||
field=models.DateTimeField(auto_now=True, help_text='Timestamp when this time-based drop record was last updated.'),
|
||||
),
|
||||
]
|
||||
|
|
@ -33,6 +33,16 @@ class Organization(models.Model):
|
|||
help_text="Display name of the organization.",
|
||||
)
|
||||
|
||||
added_at = models.DateTimeField(
|
||||
auto_now_add=True,
|
||||
db_index=True,
|
||||
help_text="Timestamp when this organization record was created.",
|
||||
)
|
||||
updated_at = models.DateTimeField(
|
||||
auto_now=True,
|
||||
help_text="Timestamp when this organization record was last updated.",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ["name"]
|
||||
indexes: ClassVar[list] = [
|
||||
|
|
@ -87,6 +97,16 @@ class Game(models.Model):
|
|||
help_text="The organization that owns this game.",
|
||||
)
|
||||
|
||||
added_at = models.DateTimeField(
|
||||
auto_now_add=True,
|
||||
db_index=True,
|
||||
help_text="Timestamp when this game record was created.",
|
||||
)
|
||||
updated_at = models.DateTimeField(
|
||||
auto_now=True,
|
||||
help_text="Timestamp when this game record was last updated.",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ["display_name"]
|
||||
indexes: ClassVar[list] = [
|
||||
|
|
@ -186,7 +206,7 @@ class DropCampaign(models.Model):
|
|||
help_text="Game associated with this campaign.",
|
||||
)
|
||||
|
||||
created_at = models.DateTimeField(
|
||||
added_at = models.DateTimeField(
|
||||
auto_now_add=True,
|
||||
db_index=True,
|
||||
help_text="Timestamp when this campaign record was created.",
|
||||
|
|
@ -288,6 +308,16 @@ class DropBenefit(models.Model):
|
|||
help_text="Type of distribution for this benefit.",
|
||||
)
|
||||
|
||||
added_at = models.DateTimeField(
|
||||
auto_now_add=True,
|
||||
db_index=True,
|
||||
help_text="Timestamp when this benefit record was created.",
|
||||
)
|
||||
updated_at = models.DateTimeField(
|
||||
auto_now=True,
|
||||
help_text="Timestamp when this benefit record was last updated.",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ["-created_at"]
|
||||
indexes: ClassVar[list] = [
|
||||
|
|
@ -351,6 +381,16 @@ class TimeBasedDrop(models.Model):
|
|||
help_text="Benefits unlocked by this drop.",
|
||||
)
|
||||
|
||||
added_at = models.DateTimeField(
|
||||
auto_now_add=True,
|
||||
db_index=True,
|
||||
help_text="Timestamp when this time-based drop record was created.",
|
||||
)
|
||||
updated_at = models.DateTimeField(
|
||||
auto_now=True,
|
||||
help_text="Timestamp when this time-based drop record was last updated.",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ["start_at"]
|
||||
indexes: ClassVar[list] = [
|
||||
|
|
@ -382,6 +422,16 @@ class DropBenefitEdge(models.Model):
|
|||
help_text="Max times this benefit can be claimed for this drop.",
|
||||
)
|
||||
|
||||
added_at = models.DateTimeField(
|
||||
auto_now_add=True,
|
||||
db_index=True,
|
||||
help_text="Timestamp when this drop-benefit edge was created.",
|
||||
)
|
||||
updated_at = models.DateTimeField(
|
||||
auto_now=True,
|
||||
help_text="Timestamp when this drop-benefit edge was last updated.",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=("drop", "benefit"), name="unique_drop_benefit"),
|
||||
|
|
@ -405,6 +455,9 @@ class NotificationSubscription(models.Model):
|
|||
notify_found = models.BooleanField(default=False)
|
||||
notify_live = models.BooleanField(default=False)
|
||||
|
||||
added_at = models.DateTimeField(auto_now_add=True, db_index=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
unique_together: ClassVar[list[tuple[str, str]]] = [
|
||||
("user", "game"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue