front_ponto_eletronico/models/record.py
2025-04-16 19:48:09 -03:00

52 lines
2.1 KiB
Python

from datetime import datetime
from sqlalchemy import Column, Integer, ForeignKey, DateTime, String
from sqlalchemy.orm import relationship
from extensions import db
class Record(db.Model):
"""Model to represent a facial recognition record with image path and count."""
__tablename__ = 'records'
id = Column(Integer, primary_key=True)
#user_id = Column(Integer, ForeignKey('user.id'), nullable=False)
#user = relationship("User", back_populates="records")
#camera_id = Column(Integer, ForeignKey('cameras.id'), nullable=False)
#camera = relationship("Camera", back_populates="records")
#space_id = Column(Integer, ForeignKey('ambiente.id'), nullable=False)
#Ambientes = relationship("Ambiente", back_populates="records")
schedule_id = Column(Integer, ForeignKey('time_schedules.id'), nullable=False)
schedule = relationship("TimeSchedule", back_populates="records")
shift_id = Column(Integer, ForeignKey('shift.id'), nullable=False)
shifts = relationship("Shift", back_populates="records")
#service_instance_id = Column(Integer, ForeignKey('service_instance.id'), nullable=False)
#service_instance = relationship("ServiceInstance", back_populates="records")
# New fields
image_path = Column(String(255), nullable=False)
record_count = Column(Integer, default=0)
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now)
deleted_at = Column(DateTime, default=None)
def to_dict(self):
return {
'id': self.id,
'user_id': self.user_id,
'camera_id': self.camera_id,
'schedule_id': self.schedule_id,
'shift_id': self.shift_id,
'space_id': self.ambiente_id,
'service_instance_id': self.service_instance_id,
'image_path': self.image_path,
'record_count': self.record_count,
'created_at': self.created_at,
'updated_at': self.updated_at,
'deleted_at': self.deleted_at
}