diff --git a/apps/diaries/interactors.py b/apps/diaries/interactors.py index 2d7c1c6..5d44a26 100644 --- a/apps/diaries/interactors.py +++ b/apps/diaries/interactors.py @@ -1,3 +1,5 @@ +import datetime + from django.contrib.auth.decorators import login_required from django.shortcuts import redirect from django.contrib import messages @@ -32,6 +34,21 @@ def create_commit(request, diary_id: int): f"?message={message}" ) + if ( + DiaryCommit.objects + .filter( + diary=diary, + message=message, + created_datetime__date=datetime.date.today() + ) + .exists() + ): + messages.error(request, message="this message already exists for today") + return redirect( + f"{reverse(viewname='diaries:detail_view', kwargs={'id': diary.id})}" + f"?message={message}" + ) + # ===== PROCESS diary_commit = DiaryCommit()