-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
29 lines (20 loc) · 980 Bytes
/
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
from sqlalchemy import Column, ForeignKey, Integer, String, DateTime, func, Float
from sqlalchemy.orm import relationship
from database import Base, engine
class CurrencyModel(Base):
__tablename__ = 'currency'
id = Column(Integer, primary_key=True, index=True)
created = Column(DateTime(timezone=True), nullable=False, server_default=func.now())
code = Column(String, nullable=False)
name = Column(String, nullable=False)
quant = Column(Integer)
values = relationship('ValueModel', back_populates='currency')
class ValueModel(Base):
__tablename__ = 'value'
id = Column(Integer, primary_key=True, index=True)
created = Column(DateTime(timezone=True), nullable=False, server_default=func.now())
value = Column(String, nullable=False)
percent = Column(Float)
currency_id = Column(Integer, ForeignKey(CurrencyModel.id))
currency = relationship('CurrencyModel', back_populates='values')
Base.metadata.create_all(engine)