From 2160a5c729a8a7e5b444dbfc6fb8ddad4c6f3ef0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 22 Sep 2021 12:33:21 -0700 Subject: [PATCH] Newly created readthroughs are active by default --- .../migrations/0099_readthrough_is_active.py | 19 +++++++++++++++++++ bookwyrm/models/readthrough.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bookwyrm/migrations/0099_readthrough_is_active.py b/bookwyrm/migrations/0099_readthrough_is_active.py index a7a2d05fd..e7b177bad 100644 --- a/bookwyrm/migrations/0099_readthrough_is_active.py +++ b/bookwyrm/migrations/0099_readthrough_is_active.py @@ -3,6 +3,19 @@ from django.db import migrations, models +def set_active_readthrough(apps, schema_editor): + """best-guess for deactivation date""" + db_alias = schema_editor.connection.alias + apps.get_model("bookwyrm", "ReadThrough").objects.using(db_alias).filter( + start_date__isnull=False, + finish_date__isnull=True, + ).update(is_active=True) + + +def reverse_func(apps, schema_editor): + """noop""" + + class Migration(migrations.Migration): dependencies = [ @@ -15,4 +28,10 @@ class Migration(migrations.Migration): name="is_active", field=models.BooleanField(default=False), ), + migrations.RunPython(set_active_readthrough, reverse_func), + migrations.AlterField( + model_name="readthrough", + name="is_active", + field=models.BooleanField(default=True), + ), ] diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index 7051deb76..fcff12a80 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -27,7 +27,7 @@ class ReadThrough(BookWyrmModel): ) start_date = models.DateTimeField(blank=True, null=True) finish_date = models.DateTimeField(blank=True, null=True) - is_active = models.BooleanField(default=False) + is_active = models.BooleanField(default=True) def save(self, *args, **kwargs): """update user active time"""