browser-go-api/models/GameRoom.py

43 lines
1.4 KiB
Python
Raw Normal View History

2019-10-04 22:00:47 +00:00
from app import db, ma
2019-10-09 05:53:37 +00:00
# TODO User >---< GameRoom
2019-10-02 03:14:21 +00:00
2019-10-09 22:42:38 +00:00
# ! Game Room >-< Users join table
2019-10-09 05:53:37 +00:00
game_rooms_users = db.Table('game_rooms_users',
db.Column('user_id', db.Integer, db.ForeignKey('users.id'), primary_key=True),
db.Column('game_rooms_id', db.Integer, db.ForeignKey('game_rooms.id'), primary_key=True)
)
2019-10-09 22:42:38 +00:00
class RoomLanguages(db.Model):
__tablename__ = "room_languages"
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String(40), nullable=False)
iso = db.Column(db.String(2), nullable=False)
2019-10-02 03:14:21 +00:00
class GameRoom(db.Model):
2019-10-02 20:55:09 +00:00
__tablename__ = "game_rooms"
__table_args__ = {'extend_existing': True}
2019-10-02 03:14:21 +00:00
2019-10-02 20:55:09 +00:00
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String(40), nullable=False)
description = db.Column(db.String(200), nullable=False)
private = db.Column(db.Boolean(), nullable=False, default=False)
2019-10-02 03:14:21 +00:00
2019-10-09 05:53:37 +00:00
# ! Foreign Keys
users = db.relationship(
'User',
secondary=game_rooms_users,
lazy='subquery',
backref=db.backref('game_rooms', lazy=True)
)
2019-10-09 22:42:38 +00:00
language = db.Column(db.Integer, db.ForeignKey("room_languages.id"), nullable=False)
2019-10-09 05:53:37 +00:00
2019-10-09 22:42:38 +00:00
def __init__(self, name, description, private=False, language=1):
2019-10-09 05:53:37 +00:00
self.name = name
self.description = description
self.private = private
self.language = language