Projekt

Obecné

Profil

Stáhnout (1.98 KB) Statistiky
| Větev: | Tag: | Revize:
1
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
2
from sqlalchemy.orm import relationship
3

    
4
from .database import Base
5

    
6

    
7
class Device(Base):
8
    __tablename__ = "devices"
9

    
10
    id = Column(Integer, primary_key=True, index=True)
11
    vendor_id = Column(Integer, index=True, nullable=False)
12
    product_id = Column(Integer, index=True, nullable=False)
13
    serial_number = Column(String, index=True, nullable=False)
14

    
15
    logs = relationship("USBLog", back_populates="device")
16
    licenses = relationship("DeviceLicense", back_populates="device_lic")
17

    
18

    
19
class USBLog(Base):
20
    __tablename__ = "usb_logs"
21

    
22
    id = Column(Integer, primary_key=True, index=True)
23
    pc_id = Column(Integer, ForeignKey("pc.id"))
24
    timestamp = Column(String, index=True, nullable=False)
25
    status = Column(String, index=True, nullable=False)
26
    device_id = Column(Integer, ForeignKey("devices.id"))
27

    
28
    device = relationship("Device", back_populates="logs")
29
    pc = relationship("PC", back_populates="logs_pc")
30

    
31

    
32
class License(Base):
33
    __tablename__ = "licenses"
34

    
35
    id = Column(Integer, primary_key=True, index=True)
36
    name = Column(String, index=True, nullable=False)
37
    expiration_date = Column(String, index=True, nullable=False)
38

    
39
    devices = relationship("DeviceLicense", back_populates="licenses")
40

    
41

    
42
class DeviceLicense(Base):
43
    __tablename__ = "devices_licenses"
44

    
45
    id = Column(Integer, primary_key=True, index=True)
46
    device_id = Column(Integer, ForeignKey("devices.id"))
47
    license_id = Column(Integer, ForeignKey("licenses.id"))
48
    assigned_datetime = Column(String, index=True, nullable=False)
49

    
50
    device_lic = relationship("Device", back_populates="licenses")
51
    licenses = relationship("License", back_populates="devices")
52

    
53

    
54
class PC(Base):
55
    __tablename__ = "pc"
56

    
57
    id = Column(Integer, primary_key=True, index=True)
58
    username = Column(String, index=True, nullable=False)
59
    hostname = Column(String, index=True, nullable=False)
60
    logs_pc = relationship("USBLog", back_populates="pc")
(5-5/6)