예제 #1
0
파일: users.py 프로젝트: jasonscjcj/Flask
class User(db.Model):
    __tablename__ = 'project_user'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50))
    email = db.Column(db.String(50))
    password = db.Column(db.String(50))
예제 #2
0
파일: models.py 프로젝트: jasonscjcj/Flask
class Article(db.Model):
    # __tablename__ = 'article'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(50))
    content = db.Column(db.String(50))
    uid = db.Column(db.Integer, db.ForeignKey('user.id'))

    author = db.relationship('User', backref='articles')

    tags = db.relationship('Tag', secondary=article_tag_table,backref='tags')
예제 #3
0
class Room(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    building = db.Column(db.Integer, unique=False)
    floor = db.Column(db.Integer, unique=False)
    roomnum = db.Column(db.Integer, unique=True)
    bookings = db.relationship('Booking', backref='Room', lazy='dynamic')

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

    def save(self):
        db.session.add(self)
        db.session.commit()
예제 #4
0
class Character(db.Model):
    __tablename__ = 'character'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(250), nullable=False)
    password = db.Column(db.String(250), nullable=False)
    item = db.relationship('Items', backref='objs', lazy=True)
    weapon = db.relationship('Weapons', backref='owner', lazy=True)

    def __init__(self, name, password):
        self.name = name
        self.password = password

    def to_json(self):
        return {
            'name': self.name,
            'password': self.password,
            'weapons': list(map(lambda x: x.to_json(), self.weapon)),
            'items': list(map(lambda x: x.to_json(), self.item)),
        }

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_db(self):
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def find_by_id(cls, id):
        try:
            area = cls.query.filter_by(id=id).first()
            return jsonify({
                'success': True,
                'count': len(area),
                'data': area.to_json()
            }), 200
        except AttributeError:
            return Errors('Unable To Find area', 404).to_json()

    @classmethod
    def all_areas(cls):
        try:
            area = cls.query.all()
            return jsonify({
                'success': True,
                'count': len(area),
                'data': list(map(lambda x: x.to_json(), area))
            }), 200
        except AttributeError:
            return Errors('Unable To Find area', 404).to_json()
예제 #5
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.String(128), unique=True)
    splitwise_token = db.Column(db.String(128), nullable=False)
    splitwise_token_secret = db.Column(db.String(128), nullable=False)

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

    def save(self):
        db.session.add(self)
        db.session.commit()

    @staticmethod
    def getUserById(user_id):
        return User.query.filter_by(user_id=user_id).first()
예제 #6
0
class Weapons(db.Model):
    __tablename__ = 'weapons'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(250), nullable=False)
    desc = db.Column(db.String(250), nullable=False)
    power = db.Column(db.Integer, nullable=False)
    character_id = db.Column(db.Integer, db.ForeignKey('character.id'))

    def to_json(self):
        return {
            'name': self.name,
            'desc': self.desc,
            'power': self.power
        }

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_db(self):
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def find_by_id(cls, id):
        try:
            weapon = cls.query.filter_by(id=id).first()
            return jsonify({
                'success': True,
                'count': 1,
                'data': weapon.to_json()
            }), 200
        except AttributeError:
            return Errors('Unable To Find weapon', 404).to_json()

    @classmethod
    def all_weapons(cls):
        try:
            weapon = cls.query.all()
            return jsonify({
                'success': True,
                'count': len(weapon),
                'data': list(map(lambda x: x.to_json(), weapon))
            }), 200
        except AttributeError:
            return Errors('Unable To Find weapon', 404).to_json()
예제 #7
0
class Seats(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    building = db.Column(db.Integer, unique=False)
    floor = db.Column(db.Integer, unique=False)
    seatnum = db.Column(db.Integer, unique=True)
    user = db.Column(db.String(100), nullable=True)
    status = db.Column(db.String(25), default='Free', nullable=True)
    teamname = db.Column(db.String(25), nullable=True)
    row = db.Column(db.Integer, unique=False)

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

    def save(self):
        db.session.add(self)
        db.session.commit()
예제 #8
0
class Booking(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    room_id = db.Column(db.Integer, db.ForeignKey('room.id'))
    start_time = db.Column(db.DateTime)
    end_time = db.Column(db.DateTime)
    user = db.Column(db.String(100), nullable=True)
예제 #9
0
파일: models.py 프로젝트: jasonscjcj/Flask
class Tag(db.Model):
    # __tablename__ = 'tag'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50))
예제 #10
0
파일: models.py 프로젝트: jasonscjcj/Flask
class User(db.Model):
    # __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50))
    email = db.Column(db.String(50))
예제 #11
0
파일: models.py 프로젝트: jasonscjcj/Flask
from middleware import db


class User(db.Model):
    # __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50))
    email = db.Column(db.String(50))


article_tag_table = db.Table(
    'article_tag',
    db.Column('article_id', db.Integer, db.ForeignKey('article.id')),
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))
)


class Article(db.Model):
    # __tablename__ = 'article'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(50))
    content = db.Column(db.String(50))
    uid = db.Column(db.Integer, db.ForeignKey('user.id'))

    author = db.relationship('User', backref='articles')

    tags = db.relationship('Tag', secondary=article_tag_table,backref='tags')