Add validators and more tests

I don't think these validators will do anything unless we use them or
are submitting a form, but they're there nonetheless
This commit is contained in:
Joel Bradshaw
2021-01-19 23:40:11 -08:00
parent edba55f7c2
commit 070fa04b63
2 changed files with 54 additions and 1 deletions

View File

@ -1,6 +1,7 @@
''' progress in a book '''
from django.db import models
from django.utils import timezone
from django.core import validators
from .base_model import BookWyrmModel
@ -13,6 +14,7 @@ class ReadThrough(BookWyrmModel):
user = models.ForeignKey('User', on_delete=models.PROTECT)
book = models.ForeignKey('Edition', on_delete=models.PROTECT)
progress = models.IntegerField(
validators=[validators.MinValueValidator(0)],
null=True,
blank=True)
progress_mode = models.CharField(
@ -43,7 +45,7 @@ class ProgressUpdate(BookWyrmModel):
''' Store progress through a book in the database. '''
user = models.ForeignKey('User', on_delete=models.PROTECT)
readthrough = models.ForeignKey('ReadThrough', on_delete=models.CASCADE)
progress = models.IntegerField()
progress = models.IntegerField(validators=[validators.MinValueValidator(0)])
mode = models.CharField(
max_length=3,
choices=ProgressMode.choices,