Adds database constraint for readthrough dates

This commit is contained in:
Mouse Reeve
2021-08-11 11:19:06 -07:00
parent 19ddcedf14
commit 1be125fc1d
2 changed files with 40 additions and 2 deletions

View File

@ -1,7 +1,8 @@
""" progress in a book """
from django.db import models
from django.utils import timezone
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
@ -41,6 +42,16 @@ class ReadThrough(BookWyrmModel):
)
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):
"""Store progress through a book in the database."""