brewman/brewman/brewman/models/fingerprint.py

33 lines
1.0 KiB
Python

import uuid
from datetime import datetime
from typing import TYPE_CHECKING, Optional
from sqlalchemy import Column, DateTime, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, relationship
from .meta import Base
if TYPE_CHECKING:
# if the target of the relationship is in another module
# that cannot normally be imported at runtime
from .employee import Employee
class Fingerprint(Base):
__tablename__ = "fingerprints"
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
employee_id: uuid.UUID = Column("employee_id", UUID(as_uuid=True), ForeignKey("employees.id"))
date: datetime = Column("date", DateTime)
employee: Mapped["Employee"] = relationship("Employee", back_populates="fingerprints")
def __init__(self, employee_id: uuid.UUID, date: datetime, id_: Optional[uuid.UUID] = None) -> None:
self.employee_id = employee_id
self.date = date
if id_ is not None:
self.id = id_