コード例 #1
0
class Notification(db.Model):
    __tablename__ = 'notifications'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    group_id = db.Column(db.Integer, db.ForeignKey('groups.id'), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    content = db.Column(db.String(255), nullable=False)
    recorded_at = db.Column(db.DateTime, nullable=False, default=datetime.now)

    def __init__(self, content):
        self.content = content

    def __repr__(self):
        return '<Notification %r>' % self.content
コード例 #2
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50), nullable=False)
    password_hash = db.Column(db.String(255), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.now, onupdate=datetime.now)
    group_id = db.Column(db.Integer, db.ForeignKey('groups.id'), nullable=False)

    attendanceLog = db.relationship('AttendanceLog', backref='users', lazy=True)
    notification = db.relationship('Notification', backref='users', lazy=True)

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

    def __init__(self, name, password, attendance_log, notification):
        self.name = name
        self.set_password(password)
        self.attendanceLog = attendance_log
        self.notification = notification

    def __repr__(self):
        return '<User %r>' % self.name
コード例 #3
0
class AttendanceStatus(db.Model):
    __tablename__ = 'status'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    group_id = db.Column(db.Integer, db.ForeignKey('groups.id'), nullable=False)
    status = db.Column(db.String(255), nullable=False)

    def __init__(self, status):
        self.status = status

    def __repr__(self):
        return '<AttendanceStatus %r>' % self.status
コード例 #4
0
class AttendanceLog(db.Model):
    __tablename__ = 'logs'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    recorded_at = db.Column(db.DateTime, nullable=False, default=datetime.now)

    status = db.relationship('AttendanceStatus', secondary=log_status, lazy='subquery', backref=db.backref('logs', lazy=True))

    def __init__(self, status):
        self.status = status

    def __repr__(self):
        return '<AttendanceLog %r>' % self.status
コード例 #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
from flasks.database import db
from werkzeug.security import generate_password_hash, check_password_hash

log_status = db.Table(
    'log_status',
    db.Column('log_id', db.Integer, db.ForeignKey('status.id'), primary_key=True),
    db.Column('status_id', db.Integer, db.ForeignKey('logs.id'), primary_key=True)
)


class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50), nullable=False)
    password_hash = db.Column(db.String(255), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.now, onupdate=datetime.now)
    group_id = db.Column(db.Integer, db.ForeignKey('groups.id'), nullable=False)

    attendanceLog = db.relationship('AttendanceLog', backref='users', lazy=True)
    notification = db.relationship('Notification', backref='users', lazy=True)

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)