Newly created readthroughs are active by default

This commit is contained in:
Mouse Reeve 2021-09-22 12:33:21 -07:00
parent 4a3bf1d92d
commit 2160a5c729
2 changed files with 20 additions and 1 deletions

View file

@ -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),
),
]

View file

@ -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"""