-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.py
73 lines (54 loc) · 2.09 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from sqlalchemy import Table, Column, Boolean, Integer, Float, String, Text, DateTime, ForeignKey
from sqlalchemy.orm import relationship, backref
from database import Base
class Directory(Base):
__tablename__ = 'directory'
id = Column(Integer, primary_key=True)
directory = Column(Text)
def __init__ (self, directory=None):
self.directory = directory
class Document(Base):
__tablename__ = 'document'
id = Column(Integer, primary_key=True)
filename = Column(Text)
title = Column(Text)
abstract = Column(Text)
directory_id = Column(Integer, ForeignKey(Directory.id))
directory = relationship('Directory', backref=backref('documents', order_by=id))
def __init__(self, filename=None, title=None, abstract=None):
self.filename = filename
self.title = title
self.abstract = abstract
class Page(Base):
__tablename__ = 'page'
id = Column(Integer, primary_key=True)
body = Column(Text)
pagenum = Column(Integer)
document_id = Column(Integer, ForeignKey(Document.id))
document = relationship('Document', backref=backref('pages', order_by=pagenum, lazy='dynamic'))
def __init__ (self, body=None, pagenum=None):
self.body = body
self.pagenum = pagenum
tagdocument = Table(
'tagdocument', Base.metadata,
Column('tag_id', Integer, ForeignKey('tag.id')),
Column('document_id', Integer, ForeignKey('document.id'))
)
class Tag(Base):
__tablename__ = 'tag'
id = Column(Integer, primary_key=True)
tag = Column(String(100))
documents = relationship('Document', secondary=tagdocument, backref=backref('tags', order_by=id))
def __init__ (self, tag=None):
self.tag = tag
authordocument = Table(
'authordocument', Base.metadata,
Column('author_id', Integer, ForeignKey('author.id')),
Column('document_id', Integer, ForeignKey('document.id'))
)
class Author(Base):
__tablename__ = 'author'
id = Column(Integer, primary_key=True)
firstname = Column(String(100))
lastname = Column(String(100))
documents = relationship('Document', secondary=authordocument, backref=backref('authors', order_by=id))