save play session summary on each change
This commit is contained in:
parent
d7dbc437fa
commit
59e783a4f7
|
@ -1,3 +1,19 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from guild.models import (
|
||||||
|
Adventure,
|
||||||
|
Character,
|
||||||
|
Player,
|
||||||
|
Reward,
|
||||||
|
Resource,
|
||||||
|
PlaySession,
|
||||||
|
PlaySessionSummaryVersion,
|
||||||
|
)
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
admin.site.register(Adventure)
|
||||||
|
admin.site.register(Character)
|
||||||
|
admin.site.register(Player)
|
||||||
|
admin.site.register(Reward)
|
||||||
|
admin.site.register(Resource)
|
||||||
|
admin.site.register(PlaySession)
|
||||||
|
admin.site.register(PlaySessionSummaryVersion)
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-06-22 18:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("guild", "0009_rename_resourceearned_reward_alter_reward_options"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="PlaySessionSummaryVersion",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("summary", models.TextField()),
|
||||||
|
(
|
||||||
|
"created_at",
|
||||||
|
models.DateTimeField(auto_now_add=True, verbose_name="created at"),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"playsession",
|
||||||
|
models.ForeignKey(
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.SET_NULL,
|
||||||
|
to="guild.playsession",
|
||||||
|
verbose_name="playsession",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
"verbose_name": "playsession summary version",
|
||||||
|
"verbose_name_plural": "playsession summary versions",
|
||||||
|
"ordering": ["-created_at"],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -132,6 +132,36 @@ class PlaySession(models.Model):
|
||||||
+ str(self.pk)
|
+ str(self.pk)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
PlaySessionSummaryVersion.objects.create(
|
||||||
|
playsession=self,
|
||||||
|
summary=self.summary,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PlaySessionSummaryVersion(models.Model):
|
||||||
|
playsession = models.ForeignKey(
|
||||||
|
"PlaySession",
|
||||||
|
verbose_name=_("playsession"),
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
null=True,
|
||||||
|
)
|
||||||
|
summary = models.TextField()
|
||||||
|
|
||||||
|
created_at = models.DateTimeField(_("created at"), auto_now_add=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _("playsession summary version")
|
||||||
|
verbose_name_plural = _("playsession summary versions")
|
||||||
|
ordering = ["-created_at"]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.playsession} - {self.created_at}"
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse("guild:playsession_detail", kwargs={"pk": self.playsession.pk})
|
||||||
|
|
||||||
|
|
||||||
class Reward(models.Model):
|
class Reward(models.Model):
|
||||||
resource = models.ForeignKey(
|
resource = models.ForeignKey(
|
||||||
|
|
Loading…
Reference in New Issue