change of comparison report of 4 model update

This commit is contained in:
2026-02-26 12:44:04 +05:30
parent cf7d1636f9
commit 568428b5d0
7 changed files with 114 additions and 28 deletions

View File

@@ -1,5 +1,9 @@
from app import db
from datetime import datetime
from sqlalchemy import event
import re
# REGEX PATTERN
PIPE_MM_PATTERN = re.compile(r"^pipe_\d+_mm$")
class Laying(db.Model):
__tablename__ = "laying"
@@ -52,3 +56,18 @@ class Laying(db.Model):
"pipe_450_mm", "pipe_500_mm", "pipe_600_mm",
"pipe_700_mm", "pipe_900_mm", "pipe_1200_mm"
]
# ===============================
# AUTO TOTAL USING REGEX
# ===============================
def calculate_laying_total(mapper, connection, target):
total = 0
for column in target.__table__.columns:
if PIPE_MM_PATTERN.match(column.name):
total += getattr(target, column.name) or 0
target.Total = total
event.listen(Laying, "before_insert", calculate_laying_total)
event.listen(Laying, "before_update", calculate_laying_total)