Add an end timestamp
This commit is contained in:
@ -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),
|
||||
),
|
||||
]
|
||||
@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user