-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
45 lines (35 loc) · 1.26 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
from sqlalchemy import Column, Integer, String, Date, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.orm import declarative_base
from sqlalchemy import Float
Base = declarative_base()
class Publisher(Base):
__tablename__ = 'publisher'
id = Column(Integer, primary_key=True)
name = Column(String)
class Book(Base):
__tablename__ = 'book'
id = Column(Integer, primary_key=True)
title = Column(String)
id_publisher = Column(Integer, ForeignKey('publisher.id'))
publisher = relationship('Publisher', backref='books')
class Shop(Base):
__tablename__ = 'shop'
id = Column(Integer, primary_key=True)
name = Column(String)
class Stock(Base):
__tablename__ = 'stock'
id = Column(Integer, primary_key=True)
id_book = Column(Integer, ForeignKey('book.id'))
id_shop = Column(Integer, ForeignKey('shop.id'))
count = Column(Integer)
book = relationship('Book', backref='stock')
shop = relationship('Shop', backref='stock')
class Sale(Base):
__tablename__ = 'sale'
id = Column(Integer, primary_key=True)
price = Column(Float)
date_sale = Column(Date)
id_stock = Column(Integer, ForeignKey('stock.id'))
count = Column(Integer)
stock = relationship('Stock', backref='sales')