-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
57 lines (43 loc) · 1.7 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, DateTime, LargeBinary
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import relationship
from dotenv import load_dotenv
import os
load_dotenv()
server = os.getenv('DB_HOST')
database = os.getenv('DB_NAME')
uid = os.getenv('DB_USER')
pwd = os.getenv('DB_PASS')
port = os.getenv('DB_PORT')
engine = create_engine(
f'mssql+pymssql://{uid}:{pwd}@{server}:{port}/{database}?charset=utf8')
# f'mssql+pymssql://{uid}:{pwd}@localhost:1433/{database}')
Base = declarative_base()
class Laptop(Base):
__tablename__ = 'laptops'
id = Column(Integer, primary_key=True)
serial_number = Column(String(50), nullable=False)
model = Column(String(50), nullable=False)
coment = Column(String(50))
company = Column(String(50), nullable=False)
status = Column(String(50), nullable=False)
class Protocol(Base):
__tablename__ = 'protocols'
id = Column(Integer, primary_key=True)
date = Column(DateTime, nullable=False)
last_name = Column(String(50), nullable=False)
laptop_id = Column(Integer, ForeignKey('laptops.id'), nullable=False)
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
charger = Column(String(50))
coment = Column(String(200))
scan_receiving = Column(LargeBinary)
scan_delivery = Column(LargeBinary)
laptop = relationship("Laptop")
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
mmd_id = Column(Integer, nullable=False)
name = Column(String(50), nullable=False)
l_name = Column(String(50), nullable=False)
domain_login = Column(String(50), nullable=False)
Base.metadata.create_all(engine)