class Comment(db.Model): # Setting the table name and # creating columns for various fields __tablename__ = 'comments' commentid = db.Column(db.Integer, primary_key=True) comment = db.Column(db.Text()) posttime = db.Column(db.DateTime) userid = db.Column(db.Integer, db.ForeignKey('users.uid')) messageid = db.Column(db.Integer, db.ForeignKey('messages.messageid')) def __init__(self, comment, posttime, userid, messageid): self.comment = comment self.posttime = posttime self.messageid = messageid self.userid = userid
class Note(db.Model): # Setting the table name and # creating columns for various fields __tablename__ = 'notes' uid = db.Column(db.Integer, primary_key=True) stored_as = db.Column(db.String(64), unique=True) file_name = db.Column(db.String(32)) owner = db.Column(db.Integer, db.ForeignKey('users.uid')) contents = db.Column(db.String(65000)) def __init__(self, file_name, owner, contents): self.file_name = file_name self.stored_as = randint(10000000000000000000, 100000000000000000000) self.owner = owner self.contents = contents
class Message (db.Model): # Setting the table name and # creating columns for various fields __tablename__ = 'messages' messageid = db.Column(db.Integer, primary_key = True) title = db.Column(db.String(455)) message = db.Column(db.Text()) posttime = db.Column(db.DateTime) courseid = db.Column(db.Integer, db.ForeignKey('courses.courseid')) userid = db.Column(db.Integer, db.ForeignKey('users.uid')) comments = db.relationship('Comment', backref='message',lazy='dynamic') def __init__(self, title, message, posttime, courseid, userid): self.title = title self.message = message self.posttime = posttime self.courseid = courseid self.userid = userid def course(self): return self.courseid def user(self): return self.userid def comment_ids(self): a = Comment.query.filter(Comment.userid == self.userid) a = a.filter(Comment.messageid == self.messageid) commentids_list = [] for item in a: print item.comment commentids_list.append(str(item.commentid)) return commentids_list
class Course (db.Model): # Setting the table name and # creating columns for various fields __tablename__ = 'courses' courseid = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(9)) alt_name = db.Column(db.String(255)) professor = db.Column(db.Integer, db.ForeignKey('users.uid')) def __init__(self, name, alt_name, professor): self.name = name self.alt_name = alt_name self.professor = professor self.user_ids = [] def user_ids(self): user_id_list = [] for user in self.users: user_id_list.append( str(user.uid) ) return user_id_list
class User (db.Model): # Setting the table name and # creating columns for various fields __tablename__ = 'users' uid = db.Column(db.Integer, primary_key = True) username = db.Column(db.String(32), unique=True) email = db.Column(db.String(64), unique=True) password = db.Column(db.String()) admin = db.Column(db.Boolean) courses = relationship("Course", secondary = subscriptionTable, backref="users") def __init__(self, username, password, email, admin): self.username = username self.password = password self.email = email self.admin = admin def course_ids(self): course_id_list = [] for course in self.courses: course_id_list.append( str(course.courseid) ) return course_id_list