Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 4911f0ea

Přidáno uživatelem Matěj Zeman před asi 2 roky(ů)

re #9577 Api code documentation.

Zobrazit rozdíly:

server/sql_app/models.py
5 5

  
6 6

  
7 7
class Device(Base):
8
    """
9
    Class defining database table devices
10
    """
8 11
    __tablename__ = "devices"
9 12

  
10 13
    id = Column(Integer, primary_key=True, index=True)
......
13 16
    serial_number = Column(String, index=True, nullable=False)
14 17
    assigned = Column(Boolean, index=True, nullable=False)
15 18

  
19
    # relationships for foreign keys, thus connecting table with usb_logs and licenses
20
    # tables
16 21
    logs = relationship("USBLog", back_populates="device")
17 22
    licenses = relationship("DeviceLicense", back_populates="device_lic")
18 23

  
19 24

  
20 25
class USBLog(Base):
26
    """
27
    Class defining database table usb_logs
28
    """
21 29
    __tablename__ = "usb_logs"
22 30

  
23 31
    id = Column(Integer, primary_key=True, index=True)
......
26 34
    status = Column(String, index=True, nullable=False)
27 35
    device_id = Column(Integer, ForeignKey("devices.id"))
28 36

  
37
    # relationships for foreign keys, thus connecting table with devices and pc
38
    # tables
29 39
    device = relationship("Device", back_populates="logs")
30 40
    pc = relationship("PC", back_populates="logs_pc")
31 41

  
32 42

  
33 43
class License(Base):
44
    """
45
    Class defining database table licenses
46
    """
34 47
    __tablename__ = "licenses"
35 48

  
36 49
    id = Column(Integer, primary_key=True, index=True)
37 50
    name = Column(String, index=True, nullable=False)
38 51
    expiration_date = Column(DateTime(timezone=True), server_default=func.now())
39 52

  
53
    # relationships for foreign keys, thus connecting table with devices table
40 54
    devices = relationship("DeviceLicense", back_populates="licenses")
41 55

  
42 56

  
43 57
class DeviceLicense(Base):
58
    """
59
    Class defining database table devices_licenses
60
    """
44 61
    __tablename__ = "devices_licenses"
45 62

  
46 63
    id = Column(Integer, primary_key=True, index=True)
......
48 65
    license_id = Column(Integer, ForeignKey("licenses.id"))
49 66
    assigned_datetime = Column(String, index=True, nullable=False)
50 67

  
68
    # relationships for foreign keys, thus connecting table with devices and licenses
69
    # tables
51 70
    device_lic = relationship("Device", back_populates="licenses")
52 71
    licenses = relationship("License", back_populates="devices")
53 72

  
54 73

  
55 74
class PC(Base):
75
    """
76
    Class defining database table pc
77
    """
56 78
    __tablename__ = "pc"
57 79

  
58 80
    id = Column(Integer, primary_key=True, index=True)
......
61 83
    assigned = Column(Boolean, index=True, nullable=False)
62 84
    team_id = Column(Integer, ForeignKey("teams.id"))
63 85

  
86
    # relationships for foreign keys, thus connecting table with teams, usb_logs and ld_logs
87
    # tables
64 88
    team = relationship("Team", back_populates="pcs")
65 89
    logs_pc = relationship("USBLog", back_populates="pc")
66 90
    ld_pc = relationship("LDLog", back_populates="ldpc")
67 91

  
68 92

  
69 93
class Team(Base):
94
    """
95
    Class defining database table teams
96
    """
70 97
    __tablename__ = "teams"
71 98

  
72 99
    id = Column(Integer, primary_key=True, index=True)
73 100
    name = Column(String, index=True, nullable=False)
101

  
102
    # relationships for foreign keys, thus connecting table with pc table
74 103
    pcs = relationship("PC", back_populates="team")
75 104

  
76 105

  
77 106
class HeadDevice(Base):
107
    """
108
    Class defining database table head_devices
109
    """
78 110
    __tablename__ = "head_devices"
79 111

  
80 112
    id = Column(Integer, primary_key=True, index=True)
81 113
    serial_number = Column(String, index=True, nullable=False)
82 114

  
115
    # relationships for foreign keys, thus connecting table with ld_logs table
83 116
    h_logs = relationship("LDLog", back_populates="head_device")
84 117

  
85 118

  
86 119
class BodyDevice(Base):
120
    """
121
    Class defining database table body_devices
122
    """
87 123
    __tablename__ = "body_devices"
88 124

  
89 125
    id = Column(Integer, primary_key=True, index=True)
90 126
    serial_number = Column(String, index=True, nullable=False)
91 127

  
128
    # relationships for foreign keys, thus connecting table with ld_logs table
92 129
    b_logs = relationship("LDLog", back_populates="body_device")
93 130

  
94 131

  
95 132
class LDLog(Base):
133
    """
134
    Class defining database table ld_logs
135
    """
96 136
    __tablename__ = "ld_logs"
97 137

  
98 138
    id = Column(Integer, primary_key=True, index=True)
......
102 142
    head_id = Column(Integer, ForeignKey("head_devices.id"))
103 143
    body_id = Column(Integer, ForeignKey("body_devices.id"))
104 144

  
145
    # relationships for foreign keys, thus connecting table with pc, head_devices and body_devices
146
    # tables
105 147
    ldpc = relationship("PC", back_populates="ld_pc")
106 148
    head_device = relationship("HeadDevice", back_populates="h_logs")
107 149
    body_device = relationship("BodyDevice", back_populates="b_logs")

Také k dispozici: Unified diff