コード例 #1
0
class Album(db.Model):
    __tablename__ = 'albums'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String, nullable=False)
    artist_id = db.Column(db.Integer, db.ForeignKey('artists.id'))
    created_at = db.Column(db.DateTime, nullable=False)
    published_at = db.Column(db.Integer, nullable=False)
    product_code = db.Column(db.Integer, nullable=False)
    created_at = db.Column(db.DateTime, nullable=False)
    updated_at = db.Column(db.DateTime, nullable=False)

    songs = db.relationship('Song', backref='album', lazy=True)
コード例 #2
0
class ClassSchedule(db.Model):
    __tablename__ = 'class_schedule'
    id = db.Column(db.Integer, primary_key=True)
    code = db.Column(db.Integer)
    class_info_id = db.Column(db.Integer, db.ForeignKey('class_info.id'))
    class_info = db.relationship('ClassInfo', back_populates='class_schedules')
    schedule_id = db.Column(db.Integer, db.ForeignKey('schedule.id'))
    schedule = db.relationship('Schedule')
    instructors = db.relationship(
        'Instructor',
        secondary=associations.instructor_class_schedule,
        back_populates='class_schedules')
    available_slots = db.Column(db.Integer)
    total_slots = db.Column(db.Integer)
    demand = db.Column(db.Integer)
    restrictions = db.Column(db.Text)
    remarks = db.Column(db.Text)
    last_updated = db.Column(db.Time)

    def __init__(self, code, class_info, schedule, instructors, available,
                 total, demand, restrictions, remarks, last_updated):
        self.code = code
        self.class_info_id = class_info.id
        self.class_info = class_info
        self.schedule_id = schedule.id
        self.schedule = schedule
        self.instructors += instructors
        self.available_slots = available
        self.total_slots = total
        self.demand = demand
        self.restrictions = restrictions
        self.remarks = remarks
        self.last_updated = last_updated

    def __repr__(self):
        return '[{}] {} {} {} {}/{}/{} {} {}'.format(
            self.code, self.class_info, self.schedule, self.instructors,
            self.available_slots, self.total_slots, self.demand,
            self.restrictions, self.remarks)
コード例 #3
0
ファイル: models.py プロジェクト: ebessa/titans-t1
class Comentario(db.Model):
    __tablename__ = 'comentarios'
    id = db.Column(db.Integer, primary_key=True)
    post = db.Column(db.Integer, db.ForeignKey('postagens.id'))
    nome = db.Column(db.String(32))
    email = db.Column(db.String(32))
    texto = db.Column(db.String(1024))

    def __init__(self, post, nome, email, texto):
        self.post = post
        self.nome = nome
        self.email = email
        self.texto = texto
コード例 #4
0
class Group(BaseModel):
    """ 组模型
    """
    __tablename__ = "group"

    name = Column("name", db.String(32), nullable=False, comment="角色名称")
    leaderId = Column("leader_id",
                      db.String(64),
                      db.ForeignKey('user.id'),
                      nullable=False,
                      comment="队长ID")
    leader = db.relationship("User")
    menbers = db.relationship('User', secondary="user_group", backref="groups")
コード例 #5
0
class LikeAlbum(db.Model):

    __tablename__ = 'like_albums'

    id = db.Column(db.Integer, primary_key=True)
    from_user_id = db.Column(db.Integer, db.ForeignKey('users.id'), index=True)
    to_album_id = db.Column(db.Integer, db.ForeignKey('albums.id'), index=True)
    create_at = db.Column(db.DateTime, default=datetime.now)

    def __init__(self, from_user_id, to_album_id):
        self.from_user_id = from_user_id
        self.to_album_id = to_album_id

    def add_like(self):
        db.session.add(self)

    def delete_like(self):
        db.session.delete(self)

    def is_liked(cls, album_id):
        return cls.query.filter_by(from_user_id=current_user.get_id(),
                                   to_album_id=album_id).count() > 0
コード例 #6
0
class adminlog(db.Model):
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    admin_id = db.Column(db.INTEGER,
                         db.ForeignKey('admin.id',
                                       onupdate="SET NULL",
                                       ondelete="SET NULL"),
                         nullable=True)
    ip = db.Column(db.String(100), nullable=False)
    addTime = db.Column(db.Date,
                        index=True,
                        nullable=False,
                        default=datetime.datetime.now())
    adminId = db.relationship("admin", back_populates='adminlogs')
コード例 #7
0
ファイル: models.py プロジェクト: maria-j-k/library_v2
class Serie(SearchableMixin, FlagMixin, db.Model):
    __sayt__ = 'name'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), index=True)
    publisher_id = db.Column(db.Integer, db.ForeignKey('publisher.id'))
    books = db.relationship('Book', backref='serie', lazy='dynamic')

    def __str__(self):
        return self.name

    @property
    def is_incorrect(self):
        return self.incorrect
コード例 #8
0
ファイル: models.py プロジェクト: maria-j-k/library_v2
class Shelf(SearchableMixin, FlagMixin, db.Model):
    __sayt__ = 'name'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64))  # wymagane
    room_id = db.Column(db.Integer, db.ForeignKey('room.id'))
    copies = db.relationship('Copy', backref='shelf', lazy='dynamic')

    def __str__(self):
        return self.name

    @property
    def is_incorrect(self):
        return self.incorrect
コード例 #9
0
class LikeJournal(db.Model):

    __tablename__ = 'like_journals'

    id = db.Column(db.Integer, primary_key=True)
    from_user_id = db.Column(db.Integer, db.ForeignKey('users.id'), index=True)
    to_journal_id = db.Column(db.Integer,
                              db.ForeignKey('journals.id'),
                              index=True)

    def __init__(self, from_user_id, to_journal_id):
        self.from_user_id = from_user_id
        self.to_journal_id = to_journal_id

    def add_like(self):
        db.session.add(self)

    def delete_like(self):
        db.session.delete(self)

    def is_liked(cls, journal_id):
        return cls.query.filter_by(from_user_id=current_user.get_id(),
                                   to_journal_id=journal_id).count() > 0
コード例 #10
0
class Item(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    description = db.Column(db.Text, nullable=True)
    date_posted = db.Column(db.DateTime(),
                            nullable=False,
                            default=datetime.now)
    favorite = db.Column(db.Boolean,
                         nullable=False,
                         server_default=expression.false())
    list_id = db.Column(db.Integer, db.ForeignKey('list.id'), nullable=False)

    def __repr__(self):
        return f"<Item('{self.title}', '{self.date_posted}', '{self.favorite}', '{self.list_id}')>"
コード例 #11
0
class Menu(BaseModel):
    """ 菜单模型
    """
    __tablename__ = "menu"

    parentId = Column("parent_id",
                      db.String(64),
                      db.ForeignKey('menu.id'),
                      comment="父ID")
    parent = db.relationship("Menu", backref="children", remote_side="Menu.id")
    name = Column("name", db.String(32), nullable=False, comment="菜单名称")
    path = Column("path", db.String(32), nullable=False, comment="菜单路径")
    icon = Column("icon", db.String(32), comment="菜单图标")
    sort = Column("sort", db.Integer, default=0, comment="排序")
コード例 #12
0
ファイル: models.py プロジェクト: jmo3/flask-resume
class Timeline(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    headline = db.Column(db.String(80))
    text = db.Column(db.Text)
    # text = db.Column(db.String(255), unique=True)
    asset_id = db.Column(db.Integer, db.ForeignKey('asset.id'))
    asset = db.relationship('Asset',
                            backref=db.backref('timelines', lazy='dynamic'))

    def __init__(self, headline, text, asset):
        self.headline = headline
        self.text = text
        self.asset = asset

    def __repr__(self):
        return "<Timeline(headline='%s', text='%s')>'" % (self.headline, self.text)
コード例 #13
0
class SatPostEffectivity(db.Model):
    __tablename__ = 'sat_post_effectivity'
    post_hash_key = db.Column(db.ForeignKey(HubPost.post_hash_key),
                              nullable=False,
                              primary_key=True)
    record_start = db.Column(db.DateTime,
                             nullable=False,
                             primary_key=True,
                             default=datetime.datetime.utcnow)
    record_end = db.Column(db.DateTime,
                           nullable=False,
                           index=True,
                           server_default='9999-12-31 00:00:00.000000')
    post_status = db.Column(db.String(32), nullable=False, default="Active")

    __mapper_args__ = {"order_by": record_start.desc()}
コード例 #14
0
ファイル: models.py プロジェクト: matix0508/FinanceApp
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    label = db.Column(db.String(32), index=True, unique=True)
    month_sum = db.Column(db.Float, default=0)
    owner = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return self.label

    def summary(self):
        output = 0
        for ex in Expense.query.filter_by(category=self.id, user=self.owner):
            output += ex.cost

        self.month_sum = output
        db.session.commit()
コード例 #15
0
class PatientBehaviours(
        db.Model
):  # How the user has behaved throughout the day, can log many behaviours per day.
    __tablename__ = 'patient_behaviours'
    behaviour_id = db.Column(db.Integer, primary_key=True)
    behaviour = db.Column(db.String(50))  # The actual behaviour.

    # Relationships ------------------------------------------------------------------------

    feelings_id = db.Column(db.Integer,
                            db.ForeignKey('patient_feelings.feelings_id'))
    feeling = db.relationship("PatientFeelings", back_populates="behaviours")

    # Class Method Override ---------------------------------------------------------------

    def get_id(self):  # Returns the behaviour_id as our primary 'id'.
        return self.behaviour_id
コード例 #16
0
class Documento(db.Model):
    __tablename__ = 'documento'

    id_documento = db.Column(
        db.Integer,
        primary_key=True,
        server_default=db.text(
            "nextval('documento_id_documento_seq'::regclass)"))
    codice = db.Column(db.String(50), unique=True, nullable=False)
    id_tipo = db.Column(db.Integer, db.ForeignKey('tipo_doc.id_tipo'))

    tipo_doc = db.relationship('TipoDoc', foreign_keys=[id_tipo])

    def __init__(self, id_documento, codice, id_tipo):
        self.id_documento = id_documento
        self.codice = codice
        self.id_tipo = id_tipo
コード例 #17
0
class PasswordResetToken(db.Model):

    __tablename__ = 'password_reset_tokens'

    id = db.Column(db.Integer, primary_key=True)
    token = db.Column(
        db.String(64),
        unique=True,
        index=True,
        server_default=str(uuid4)
    )
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    expire_at = db.Column(db.DateTime, default=datetime.now)
    create_at = db.Column(db.DateTime, default=datetime.now)
    update_at = db.Column(db.DateTime, default=datetime.now)

    def __init__(self, token, user_id, expire_at):
        self.token = token
        self.user_id = user_id
        self.expire_at = expire_at

    @classmethod
    def publish_token(cls, user):
        # パスワード設定用のURLを生成
        token = str(uuid4())
        new_token = cls(
            token,
            user.id,
            datetime.now() + timedelta(days=1)
        )
        db.session.add(new_token)
        return token
    
    @classmethod
    def get_user_id_by_token(cls, token):
        now = datetime.now()
        record = cls.query.filter_by(token=str(token)).filter(cls.expire_at > now).first()
        if record:
            return record.user_id
        else:
            return None
        

    @classmethod
    def delete_token(cls, token):
        cls.query.filter_by(token=str(token)).delete()
コード例 #18
0
ファイル: models.py プロジェクト: weijiayun/blog
class Post(db.Model):
    __searchable__ = ['body']

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(60))
    body = db.Column(db.String(1400))
    timestamp = db.Column(db.DateTime)
    comments = db.relationship('Comment', backref='topost', lazy='dynamic')
    likes = db.relationship('Like', backref='topost', lazy='dynamic')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def OutLikers(self):
        likes = self.likes.order_by(Like.timestamp.desc()).all()
        return (i.byuser for i in likes)

    def __repr__(self):
        return '<Post %r>' % (self.body)
コード例 #19
0
class SatPostContent(db.Model):
    __tablename__ = 'sat_post_content'
    post_hash_key = db.Column(db.ForeignKey(HubPost.post_hash_key),
                              nullable=False,
                              primary_key=True)
    record_start = db.Column(db.DateTime,
                             nullable=False,
                             primary_key=True,
                             default=datetime.datetime.utcnow)
    record_end = db.Column(db.DateTime,
                           nullable=False,
                           index=True,
                           server_default='9999-12-31 00:00:00.000000')
    title = db.Column(db.String, nullable=False)
    body = db.Column(db.String, nullable=False)

    __mapper_args__ = {"order_by": record_start.desc()}
コード例 #20
0
class Location(db.Model):
    """Stores the location & time"""
    __tablename__ = 'Locations'

    id = db.Column(db.Integer, primary_key=True)
    person_id = db.Column(db.Integer, db.ForeignKey('People.id'))

    #This stores the long, lat and time.
    longitude = db.Column(db.Float)
    latitude = db.Column(db.Float)
    time = db.Column(db.String(16))

    # Relationship store the person's locations as a list in the person's table in the people table.
    person = db.relationship('Person',
                             backref=db.backref('Locations',
                                                lazy='dynamic',
                                                collection_class=list))
コード例 #21
0
class Post(db.Model):
    __tablename__ = 'posts'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(120), nullable=False)
    body = db.Column(db.Text(), nullable=False)
    created = db.Column(db.DateTime(), nullable=False,
                     server_default=func.now())    
    author_id = db.Column(db.Integer,
                          db.ForeignKey('users.id'),
                          nullable=False)
    author = db.relationship('User', lazy=True,
                             backref=db.backref('posts', lazy=True))
    

    def __repr__(self):
        return '<Post %r %r %r %r>' % (self.title, self.body, self.created,
                                       self.author.username)
コード例 #22
0
class Person(db.Model):
    __tablename__ = 'persons'
    __table_args__ = (db.PrimaryKeyConstraint('id'), {
        'mysql_engine': 'InnoDB'
    })
    id = db.Column(db.String(36), default=_get_uuid)
    name = db.Column(db.String(64), nullable=False)  # 名前
    display = db.Column(db.String(64), nullable=True)  # 表示名
    idm = db.Column(db.String(16), unique=True)  # Ferica IDM
    enabled = db.Column(db.Boolean, nullable=False)  # 有効化
    staff = db.Column(db.Boolean, nullable=False)  # 職員
    timerule_id = db.Column(db.String(36),
                            db.ForeignKey('timerules.id'))  # タイムテーブル
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)
    recipient = db.relationship('Recipient',
                                uselist=False,
                                back_populates="person")

    def get_display(self):
        if self.display is None:
            return self.name
        return self.display

    def is_idm(self):
        if bool(self.idm):
            return self.id == cache.get('person.id')
        return True

    def populate_form(self, form):
        form.populate_obj(self)
        if not bool(self.id):
            self.id = None
        if not bool(self.display):
            self.display = None
        if not bool(self.idm):
            self.idm = None

    @classmethod
    def get(cls, id):
        return cls.query.filter(cls.id == id).first()

    @classmethod
    def get_idm(cls, idm):
        return cls.query.filter(cls.idm == idm).first()
コード例 #23
0
ファイル: models.py プロジェクト: SkeyRahaman/kharchakhata
class Android(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    app_name = db.Column(db.String(40), nullable=False)
    app_logo_url = db.Column(db.String(100))
    dev_name = db.Column(db.String(60), nullable=False)
    intro1 = db.Column(db.String(80), nullable=False)
    intro2 = db.Column(db.String(80), nullable=False)
    app_url = db.Column(db.String(100), nullable=False)
    user_id = db.Column(db.Integer,
                        db.ForeignKey("users.id"),
                        nullable=False,
                        unique=True)
    dev_profile_url = db.Column(db.String(100), default="#")
    date_time = db.Column(db.DateTime, nullable=False)
    approved = db.Column(db.Integer, nullable=False, default=0)

    def __repr__(self):
        return '<Android name %r>' % self.app_name
コード例 #24
0
ファイル: tweet.py プロジェクト: aqml15/Twitter-Clone-Project
class Tweet(db.Model):
    __tablename__ = 'Tweet'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String, nullable=False)
    body = db.Column(db.String, nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('User.id'), nullable=False)
    user = db.relationship('User', foreign_keys=[user_id])

    def serialize(self):
        return {
            'id': self.id,
            'title': self.title,
            'body': self.body,
            'created_at': self.created_at,
            'updated_at': self.updated_at,
            'user_id': self.user_id
        }
コード例 #25
0
class InvestmentAccount(db.Model):
    __tablename__ = "investment_account"
    id = db.Column(db.Integer, primary_key=True)
    """InvestmentAccount's id"""
    name = db.Column(db.String, nullable=False)
    """InvestmentAccount's given display name"""
    taxable = db.Column(db.Boolean, nullable=False)
    """If true that means this investment account is a taxable account"""
    user_id = db.Column(db.Integer,
                        db.ForeignKey('portfolio_user.id'),
                        nullable=False)
    """The id of the user that owns this investment account"""
    transactions = db.relationship('StockTransaction',
                                   backref="investment_account")
    """The stock transactions that belong to this investment account"""
    def __iter__(self):
        yield ('id', self.id)
        yield ('name', self.name)
        yield ('taxable', self.taxable)
コード例 #26
0
class Entry(db.Model):
    __tablename__ = "Entries"
    id =  db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime, nullable=False, default=datetime.now)
    author_id = db.Column(db.Integer, db.ForeignKey(User.id), nullable=False)
    mood_rate = db.Column(db.Integer, nullable=False)
    title = db.Column(db.Text)
    journal = db.Column(db.Text)

    #author = db.relationship('User', backref=db.backref('entries', lazy=True))

    def __init__(self, mood_rate, title, journal, author):
        self.mood_rate = mood_rate
        self.title = title
        self.journal = journal
        self.author = author

    def __repr__(self):
        return '<Entry {}>'.format(self.journal[:30])
コード例 #27
0
ファイル: models.py プロジェクト: jmo3/flask-resume
class Entry(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    headline = db.Column(db.String(80))
    startDate = db.Column(db.String(80))
    endDate = db.Column(db.String(80))
    text = db.Column(db.Text)
    asset_id = db.Column(db.Integer, db.ForeignKey('asset.id'))
    asset = db.relationship('Asset',
                            backref=db.backref('entries', lazy='dynamic'))

    def __init__(self, headline, startDate, endDate, text, asset):
        self.headline = headline
        self.startDate = startDate
        self.endDate = endDate
        self.text = text
        self.asset = asset

    def __repr__(self):
        return "<Headline(headline='%s', startDate='%s', endDate='%s', text='%s')>" % (self.headline, self.startDate, self.endDate, self.text)
コード例 #28
0
class Blog(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  author_id = db.Column(db.ForeignKey(User.id), nullable=False)
  title = db.Column(db.String, nullable=False)
  summary = db.Column(db.String, nullable=False)
  content = db.Column(db.String, nullable=False)
  image = db.Column(db.String)
  created_at = db.Column(db.DateTime, nullable=False, server_default=db.func.current_timestamp())

  # User object backed by author_id
  # lazy="joined" means the user is returned with the user in one query
  author = db.relationship(User, lazy="joined", backref="blogs")

  @property
  def update_url(self):
    return url_for("manage.update", id=self.id)

  @property
  def delete_url(self):
    return url_for("manage.delete", id=self.id)
コード例 #29
0
class Post(db.Model):

    __tablename__ = 'posts'

    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.String(400), index=True)
    username = db.Column(db.String(64), index=True)
    time = db.Column(db.String(100))
    page_id = db.Column(db.Integer, db.ForeignKey('createpages.id'))

    def __init__(self, content, username, time, page_id):
        self.content = content
        self.username = username
        self.time = time.strftime('%Y年%m月%d日 %H:%M:%S')
        self.page_id = page_id

    def add_post(self):
        with db.session.begin(subtransactions=True):
            db.session.add(self)
        db.session.commit()
コード例 #30
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    author_id = db.Column(db.ForeignKey(Users.id), nullable=False)
    created = db.Column(db.DateTime,
                        nullable=False,
                        server_default=db.func.current_timestamp())
    title = db.Column(db.String, nullable=False)
    body = db.Column(db.String, nullable=False)

    # Users object backed by author_id
    # lazy="joined" means the user is returned with the post in one query
    author = db.relationship(Users, lazy="joined", backref="posts")

    @property
    def update_url(self):
        return url_for("blog.update", id=self.id)

    @property
    def delete_url(self):
        return url_for("blog.delete", id=self.id)