fix aud search on center
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# backend/models.py
|
||||
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship, declarative_base
|
||||
import datetime
|
||||
|
||||
@@ -98,3 +98,47 @@ class Zametki(Base):
|
||||
txtzam = Column(String(10000))
|
||||
created_date = Column(DateTime, default=datetime.datetime.utcnow)
|
||||
rmdt = Column(DateTime)
|
||||
|
||||
|
||||
class InspectionSession(Base):
|
||||
__tablename__ = 'inspection_sessions'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
started_at = Column(DateTime, nullable=False)
|
||||
completed_at = Column(DateTime, nullable=True)
|
||||
aud_id = Column(Integer, ForeignKey("auditories.id"), nullable=True) # null = всё подряд
|
||||
|
||||
# Relationships
|
||||
user = relationship("User")
|
||||
auditory = relationship("Auditory")
|
||||
records = relationship("InspectionRecord", back_populates="session")
|
||||
unknown_barcodes = relationship("UnknownBarcode", back_populates="session")
|
||||
|
||||
|
||||
class InspectionRecord(Base):
|
||||
__tablename__ = 'inspection_records'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
session_id = Column(Integer, ForeignKey("inspection_sessions.id"), nullable=False)
|
||||
oborud_id = Column(Integer, ForeignKey("oboruds.id"), nullable=False)
|
||||
checked_at = Column(DateTime, nullable=False) # обновляется при повторном сканировании
|
||||
|
||||
# Relationships
|
||||
session = relationship("InspectionSession", back_populates="records")
|
||||
oborud = relationship("Oboruds")
|
||||
|
||||
# Уникальное ограничение: одна запись на оборудование в рамках сессии
|
||||
__table_args__ = (UniqueConstraint('session_id', 'oborud_id', name='_session_oborud_uc'),)
|
||||
|
||||
|
||||
class UnknownBarcode(Base):
|
||||
__tablename__ = 'unknown_barcodes'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
session_id = Column(Integer, ForeignKey("inspection_sessions.id"), nullable=False)
|
||||
barcode = Column(String(100), nullable=False)
|
||||
scanned_at = Column(DateTime, nullable=False)
|
||||
|
||||
# Relationships
|
||||
session = relationship("InspectionSession", back_populates="unknown_barcodes")
|
||||
|
||||
Reference in New Issue
Block a user