diff --git a/bookwyrm/migrations/0099_readthrough_is_active.py b/bookwyrm/migrations/0099_readthrough_is_active.py index a7a2d05f..e7b177ba 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 7051deb7..fcff12a8 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"""