forked from the-gigi/book-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
45 lines (34 loc) · 1.34 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 datetime import datetime
from sqlalchemy import (Column,
DateTime,
ForeignKey,
Integer,
String,
Boolean,
Index)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
Base = declarative_base()
metadata = Base.metadata
class Book(Base):
__tablename__ = 'book'
id = Column(Integer, primary_key=True)
name = Column(String(256), unique=True, nullable=False, index=True)
isbn = Column(String(13), nullable=False)
url = Column(String(1024), nullable=False)
track = Column(Boolean, default=True, index=True)
class Category(Base):
__tablename__ = 'category'
id = Column(Integer, primary_key=True)
name = Column(String(1024))
class Rank(Base):
__tablename__ = 'rank'
id = Column(Integer, primary_key=True)
book_id = Column(ForeignKey('book.id'), nullable=False)
category_id = Column(ForeignKey('category.id'), nullable=False)
rank = Column(Integer, nullable=False)
change = Column(Integer)
timestamp = Column(DateTime, nullable=False, default=datetime.now)
book = relationship('Book')
category = relationship('Category')
Index('ix_book_category_timestamp', 'book', 'category', 'timestamp', unique=True)