Show error message when start and finish date is invalid

This commit is contained in:
Mouse Reeve
2022-01-11 10:22:01 -08:00
parent 9521c477b2
commit cdaf0fe8e3
4 changed files with 78 additions and 8 deletions

View File

@@ -480,6 +480,16 @@ class SortListForm(forms.Form):
)
class ReadThroughForm(CustomForm):
def clean(self):
"""make sure the email isn't in use by a registered user"""
cleaned_data = super().clean()
start_date = cleaned_data.get("start_date")
finish_date = cleaned_data.get("finish_date")
if start_date > finish_date:
self.add_error(
"finish_date", _("Reading finish date cannot be before start date.")
)
class Meta:
model = models.ReadThrough
fields = ["user", "book", "start_date", "finish_date"]