From fd79416ce94ee7440483e0a380b6945b4544e6c4 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 13 Aug 2024 18:35:10 -0300 Subject: [PATCH] Fixing double creating of report --- report/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/report/views.py b/report/views.py index 5112764..ecd8d98 100644 --- a/report/views.py +++ b/report/views.py @@ -1,7 +1,7 @@ import datetime import pandas as pd import zipfile - +from django.utils import timezone from django.forms import inlineformset_factory from io import BytesIO from django.http import JsonResponse @@ -29,7 +29,8 @@ def add_report(request): metrics_set = list(map(int, report_form.data.getlist('metrics_related', []))) operation_formset = get_operation_formset() if request.method == "POST": - report_exists = Report.objects.filter(created_by__user=request.user, description=report_form.data.get("description")).exists() + timediff = timezone.now() - datetime.timedelta(hours=24) + report_exists = Report.objects.filter(created_by__user=request.user, description=report_form.data.get("description"), created_at__lte=timediff).exists() operation_metrics = operation_formset(request.POST, prefix='Operation') if not report_exists: if report_form.is_valid() and operation_metrics.is_valid():