-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
123 lines (96 loc) · 4.23 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
import os
import sys
from sqlalchemy import Column, ForeignKey, Integer, String, DateTime, Boolean, Text
from sqlalchemy.orm import backref, relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
Model = declarative_base()
class User(Model):
'''
roles
4 - SU
3 - admin
2 - teacher
1 - study
0 - listener
'''
__tablename__ = "users"
id = Column(Integer, primary_key=True)
card_id = Column(String(30), unique=True, nullable=False)
finger_id = Column(Integer, nullable=False, default=0)
#password = Column(String(240), nullable=False)
registered_on = Column(DateTime, nullable=False)
role = Column(Integer, nullable=False, default=0)
confirmed = Column(Boolean, nullable=False, default=False)
confirmed_on = Column(DateTime, nullable=True)
# classroom = Column(Integer, ForeignKey('users.id'), nullable = True)
# info = relationship("User_Bio", backref="user", lazy='dynamic')
children = relationship("Users_Courses", back_populates="parent" , cascade="delete, delete-orphan")
'''
def __init__(self, email, password, confirmed,
paid=False, role=1, confirmed_on=None):
self.email = email
self.password = bcrypt.generate_password_hash(password)
self.registered_on = datetime.datetime.now()
self.role = role
self.confirmed = confirmed
self.confirmed_on = confirmed_on
'''
class User_Bio(Model):
__tablename__ = "user_bio"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('users.id'), unique=True)
name = Column(String(90), nullable=False)
surname = Column(String(90), nullable=False)
bio = Column(Text, nullable=True, default=u'Вы пока ничего не рассказали о себе!')
hobbies = Column(Text, nullable=True, default=u'Мы пока ничего не знаем о Ваших увлечениях!')
photo = Column(Text, nullable=False, default='/static/img/logo_old.png')
user = relationship("User", backref=backref("info", uselist=False), lazy='joined')
'''
def __init__(self, name, surname, bio,
hobbies, photo):
self.name = name
self.surname = surname
self.bio = bio
self.hobbies = hobbies
self.photo = photo
'''
class Courses(Model):
__tablename__ = "courses"
id = Column(Integer, primary_key=True)
title = Column(String(120), nullable=False)
slug = Column(String(120), nullable=False)
desc_short = Column(String(240), nullable=False)
desc_full = Column(Text, nullable=False)
img = Column(String(120), nullable=False)
age = Column(Integer, nullable=False)
difficulty = Column(Integer, nullable=False)
published = Column(Boolean, default=False)
teacher = Column(Integer, ForeignKey('users.id'), nullable=True)
parents = relationship("Users_Courses", back_populates="child", cascade="save-update, merge, delete")
#lessons = relationship("Lessons", backref=backref("course"), lazy='joined')
class Users_Courses(Model):
__tablename__ = 'uhs'
id = Column(Integer, primary_key=True)
left_id = Column(Integer, ForeignKey('users.id'))
right_id = Column(Integer, ForeignKey('courses.id'))
earned_xp = Column(Integer, nullable=True)
last_update = Column(DateTime, nullable=False)
child = relationship("Courses", back_populates="parents")
parent = relationship("User", back_populates="children")
'''
in_class = Table ('in_class',
Column('user_id', Integer, ForeignKey('users.id'), primary_key=True),
Column('class_id', Integer, ForeignKey('classroom.id'), primary_key=True)
)
class ClassRoom (Model):
__tablename__ = "classroom"
id = Column(Integer, primary_key=True)
title = Column(String(120), nullable=False)
day = Column(Text, nullable=True)
time = Column(Time, nullable=True)
course = Column(Integer, ForeignKey('courses.id'), nullable=False)
users = relationship('User', secondary=in_class, lazy='subquery',
backref=backref('classrooms', lazy=True))
'''