mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-19 14:48:59 +00:00
Adds database constraint for readthrough dates
This commit is contained in:
parent
19ddcedf14
commit
1be125fc1d
2 changed files with 40 additions and 2 deletions
27
bookwyrm/migrations/0083_auto_20210811_1817.py
Normal file
27
bookwyrm/migrations/0083_auto_20210811_1817.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# Generated by Django 3.2.4 on 2021-08-11 18:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.expressions
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("bookwyrm", "0082_auto_20210806_2324"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="readthrough",
|
||||||
|
options={"ordering": ("-start_date",)},
|
||||||
|
),
|
||||||
|
migrations.AddConstraint(
|
||||||
|
model_name="readthrough",
|
||||||
|
constraint=models.CheckConstraint(
|
||||||
|
check=models.Q(
|
||||||
|
("finish_date__gte", django.db.models.expressions.F("start_date"))
|
||||||
|
),
|
||||||
|
name="chronology",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,7 +1,8 @@
|
||||||
""" progress in a book """
|
""" progress in a book """
|
||||||
from django.db import models
|
|
||||||
from django.utils import timezone
|
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
|
from django.db import models
|
||||||
|
from django.db.models import F, Q
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
from .base_model import BookWyrmModel
|
from .base_model import BookWyrmModel
|
||||||
|
|
||||||
|
@ -41,6 +42,16 @@ class ReadThrough(BookWyrmModel):
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Don't let readthroughs end before they start"""
|
||||||
|
|
||||||
|
constraints = [
|
||||||
|
models.CheckConstraint(
|
||||||
|
check=Q(finish_date__gte=F("start_date")), name="chronology"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
ordering = ("-start_date",)
|
||||||
|
|
||||||
|
|
||||||
class ProgressUpdate(BookWyrmModel):
|
class ProgressUpdate(BookWyrmModel):
|
||||||
"""Store progress through a book in the database."""
|
"""Store progress through a book in the database."""
|
||||||
|
|
Loading…
Reference in a new issue