mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-19 22:56:38 +00:00
Normalize readthrough dates in advance of migration
This commit is contained in:
parent
3f2f8f0e50
commit
2c78eddbeb
1 changed files with 13 additions and 0 deletions
|
@ -4,6 +4,18 @@ from django.db import migrations, models
|
|||
import django.db.models.expressions
|
||||
|
||||
|
||||
def normalize_readthrough_dates(app_registry, schema_editor):
|
||||
"""bih"""
|
||||
db_alias = schema_editor.connection.alias
|
||||
app_registry.get_model("bookwyrm", "Readthrough").objects.using(db_alias).filter(
|
||||
start_date__gt=models.F("finish_date")
|
||||
).update(start_date=models.F("finish_date"))
|
||||
|
||||
|
||||
def reverse_func(apps, schema_editor):
|
||||
"""nothing to do here"""
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
|
@ -11,6 +23,7 @@ class Migration(migrations.Migration):
|
|||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(normalize_readthrough_dates, reverse_func),
|
||||
migrations.AlterModelOptions(
|
||||
name="readthrough",
|
||||
options={"ordering": ("-start_date",)},
|
||||
|
|
Loading…
Reference in a new issue