class Course(db.Model): id = db.Column(db.Integer(), primary_key=True) subject = db.Column(db.Integer(), db.ForeignKey('subject.id')) number = db.Column(db.String(60), nullable=False) school = db.Column(db.Integer(), db.ForeignKey('school.id')) def __unicode__(self): return unicode(self.subject) + " " + self.number
class DiscussionPost(db.Model): id = db.Column(db.Integer(), primary_key=True) text = db.Column(db.Text(), nullable = False) user = db.Column(db.Integer(), db.ForeignKey('user.id')) date_time = db.Column(db.DateTime(), nullable = False) topic = db.Column(db.Integer(), db.ForeignKey('topic.id')) ups = db.Column(db.Integer(), nullable = False, default = 0) downs = db.Column(db.Integer(), nullable = False, default = 0) deleted = db.Column(db.Boolean(), nullable=False, default = False) def __unicode__(self): return unicode(self.user) + " posted " + unicode(self.text) + " to " + unicode(self.topic)
class TopicTree(db.Model): id = db.Column(db.Integer(), primary_key=True) subject = db.Column(db.Integer(), db.ForeignKey('subject.id')) #represents the json tree representation {'parent_topic' : {'child_topic' : {'grandchild_topic' : None, 'grandchild_topic2' : None}}} tree_representation = db.Column(db.String(1000), nullable=False) def __unicode__(self): return self.tree_representation
class ContentToTopic(db.Model): id = db.Column(db.Integer(), primary_key=True) content = db.Column(db.Text(), nullable = False) links = db.Column(db.Text(), nullable = False, default = '') topic = db.Column(db.Integer(), db.ForeignKey('topic.id')) version_number = db.Column(db.Integer(), nullable = False) def __unicode__(self): return unicode(self.topic) + "'s content"
unique=False, nullable=True) hosts = db.relationship('Host', secondary='user_host_relation', backref=db.backref('hosts', lazy='dynamic'), lazy='dynamic', passive_deletes=True) def set_password(self, password): self.password = generate_password_hash(password, method='sha256') def check_password(self, password): return check_password_hash(self.password, password) def __repr__(self): return '<User {}>'.format(self.name) user_host_relation = db.Table( 'user_host_relation', db.Column('user_id', db.Integer, db.ForeignKey('user.id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True), db.Column('host_id', db.Integer, db.ForeignKey('host.id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True)) db.create_all()
from application_config import app, db from flask.ext.security import RoleMixin, UserMixin, SQLAlchemyUserDatastore roles_users = db.Table( 'roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) class User(db.Model, UserMixin): id = db.Column(db.Integer(), primary_key=True) email = db.Column(db.String(120), index=True, unique=True, nullable=False) firstname = db.Column(db.String(30), index=True, nullable=False) lastname = db.Column(db.String(30), index=True, nullable=False) password = db.Column(db.String(255), nullable=False) active = db.Column(db.Boolean()) website = db.Column(db.String(120)) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('user', lazy='dynamic')) grades = db.relationship('Grade', lazy='dynamic', backref='user') programs = db.relationship('Program', lazy='dynamic', backref='user') code_revisions = db.relationship('CodeRevision', lazy='dynamic',
class TopicToCourse(db.Model): id = db.Column(db.Integer(), primary_key=True) topic = db.Column(db.Integer(), db.ForeignKey('topic.id')) course = db.Column(db.Integer(), db.ForeignKey('course.id')) def __unicode__(self): return unicode(self.course) + " has this topic: " + unicode(self.topic)
class TopicToSubject(db.Model): id = db.Column(db.Integer(), primary_key=True) topic = db.Column(db.Integer(), db.ForeignKey('topic.id')) subject = db.Column(db.Integer(), db.ForeignKey('subject.id')) def __unicode__(self): return unicode(self.subject) + "'s " + unicode(self.topic)