Esempio n. 1
0
class Student(db.Model):
    id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    group_id = db.Column(db.Integer, db.ForeignKey('group.id'), nullable=True)

    # чтобы это заработало, нужно указать какой из ключей выше является внешним ключем
    userData = db.relationship('User', backref='student', uselist=False)
    group = db.relationship('Group', backref='student', uselist=False)

    def __repr__(self):
        return f'{self.id}'
Esempio n. 2
0
class Teacher(db.Model):
    id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    department_id = db.Column(db.Integer, db.ForeignKey('department.id'))

    # чтобы это заработало, нужно указать какой из ключей выше является внешним ключем
    department = db.relationship('Department',
                                 backref='teacher',
                                 uselist=False)
    userData = db.relationship('User', backref='teacher', uselist=False)

    def __repr__(self):
        return f'{self.id}'
Esempio n. 3
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow())

    owner_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    owner = db.relationship('User', backref=db.backref('creater', lazy=True))

    article_id = db.Column(db.Integer, db.ForeignKey('article.id'))
    article = db.relationship('Article',
                              backref=db.backref('article', lazy=True))

    def __repr__(self):
        return '<Comment %r' % self.id
Esempio n. 4
0
class Tag(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(32), nullable=False)

    message_id = db.Column(db.Integer,
                           db.ForeignKey('message.id'),
                           nullable=False)
    message = db.relationship('Message', backref=db.backref('tags', lazy=True))
Esempio n. 5
0
class Discipline(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=True)
    teacher_id = db.Column(db.Integer,
                           db.ForeignKey('teacher.id'),
                           nullable=True)

    teacher = db.relationship('Teacher', backref='discipline', uselist=False)

    def __repr__(self):
        return f'{self.id} {self.teacher_id} {self.name}'
Esempio n. 6
0
class Department(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    faculty_id = db.Column(db.Integer,
                           db.ForeignKey('faculty.id'),
                           nullable=True)
    name = db.Column(db.String(255), nullable=True)

    faculty = db.relationship('Faculty', backref='department', uselist=False)

    def __repr__(self):
        return f'\nid = {self.id}\tfaculty_id={self.faculty_id} name={self.name}'
Esempio n. 7
0
class Group(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    degree_programm_id = db.Column(db.Integer,
                                   db.ForeignKey('degree_programm.id'))
    name = db.Column(db.String(255), nullable=True)
    disciplines = db.Column(db.String, nullable=True)

    # чтобы это заработало, нужно указать какой из ключей выше является внешним ключем
    degreeProgramm = db.relationship('DegreeProgramm',
                                     backref='group',
                                     uselist=False)

    def __repr__(self):
        return f'{self.id} {self.name}'
Esempio n. 8
0
class Article(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(128), nullable=False)
    cut = db.Column(db.String(128), nullable=False)
    text = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow())

    owner_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    owner = db.relationship('User', backref=db.backref('owner', lazy=True))

    tags = db.relationship('Tag',
                           secondary=tags,
                           lazy='subquery',
                           backref=db.backref('articles', lazy=True))

    comments = db.relationship('Comment',
                               lazy=True,
                               backref=db.backref('comments', lazy=True))

    def __repr__(self):
        return '<Article %r>' % self.id
Esempio n. 9
0
from datetime import datetime

from flask_login import UserMixin

from sweater import db, login_manager

tags = db.Table(
    'tags',
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True),
    db.Column('article_id',
              db.Integer,
              db.ForeignKey('article.id'),
              primary_key=True))


class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    login = db.Column(db.String(64), nullable=False, unique=True)
    email = db.Column(db.String(128), nullable=False, unique=True)
    password = db.Column(db.String(255), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow())

    def __repr__(self):
        return '<User %r>' % self.id


class Article(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(128), nullable=False)
    cut = db.Column(db.String(128), nullable=False)
    text = db.Column(db.Text, nullable=False)