Add an end timestamp

This commit is contained in:
2023-04-02 23:57:55 -04:00
parent 5db8bf0329
commit fe4faee7aa
2 changed files with 27 additions and 1 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2023-04-03 03:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("scrobbles", "0035_scrobble_videogame_save_data"),
]
operations = [
migrations.AddField(
model_name="scrobble",
name="stop_timestamp",
field=models.DateTimeField(blank=True, null=True),
),
]

View File

@ -430,6 +430,7 @@ class Scrobble(TimeStampedModel):
# Time keeping
timestamp = models.DateTimeField(**BNULL)
stop_timestamp = models.DateTimeField(**BNULL)
playback_position_ticks = models.PositiveBigIntegerField(**BNULL)
playback_position_seconds = models.IntegerField(**BNULL)
@ -650,9 +651,16 @@ class Scrobble(TimeStampedModel):
check_scrobble_for_finish(self)
if scrobble_status != "resumed":
scrobble_data["stop_timestamp"] = (
scrobble_data.pop("timestamp", None) or timezone.now()
)
update_fields = []
for key, value in scrobble_data.items():
setattr(self, key, value)
self.save()
update_fields.append(key)
self.save(update_fields=update_fields)
return self