-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
39 lines (28 loc) · 1.04 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
import os
from sqlalchemy import Column, ForeignKey, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from simplerestapi.endpoint import ConstructEndpoint, Endpoint
Base = declarative_base(metaclass=ConstructEndpoint)
class CustomUser(Base, Endpoint):
id = Column(Integer, primary_key=True)
name = Column(String)
surname = Column(String)
age = Column(Integer)
car = relationship('Car')
class ConfigEndpoint:
join_related = ['car']
class Car(Base, Endpoint):
id = Column(Integer, primary_key=True)
name_model = Column(String)
production = Column(String)
year = Column(Integer)
customuser_id = Column(Integer, ForeignKey('customuser.id'))
customuser = relationship('CustomUser')
class ConfigEndpoint:
join_related = ['customuser']
if __name__ == '__main__':
print('Start creating tables')
engine = create_engine(os.environ['DB_URL'])
Base.metadata.create_all(engine)
print('Tables created')