-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
73 lines (52 loc) · 1.77 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 (create_engine, Column, Integer, String, ForeignKey)
from sqlalchemy.orm import (scoped_session, sessionmaker, relationship)
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('sqlite:///atividades.db')
db_session = scoped_session(sessionmaker(autocmmit=True,
bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()
class Pessoas(Base):
__tablename__ = 'pessoas'
id = Column(Integer, primary_key=True)
nome = Column(String(40), index=True)
idade = Column(Integer)
def __repr__(self):
return '<Pessoa {}>'.format((self.nome))
def save(self):
db_session.add(self)
db_session.commit()
def delete(self):
db_session.delete(self)
db_session.commit()
class Atividades(Base):
__tablename__ = 'atividades'
id = Column(Integer, primary_key=True)
nome = Column(String(80))
pessoa_id = Column(Integer, ForeignKey('pessoas.id'))
pessoa = relationship("Pessoas")
def __repr__(self):
return '<Atividades {}>'.format((self.nome))
def save(self):
db_session.add(self)
db_session.commit()
def delete(self):
db_session.delete(self)
db_session.commit()
class Usuarios(Base):
__tablename__ = 'usuarios'
id = Column(Integer, primary_key=True)
login = Column(String(20), unique=True)
senha = Column(String(20))
def __repr__(self):
return '<Usuario {}>'.format(self.login)
def save(self):
db_session.add(self)
db_session.commit()
def delete(self):
db_session.delete(self)
db_session.commit()
def init_db():
Base.metadata.create_all(bind=engine)
if __name__ == '__main__':
init_db()