browser-go-api/models/GameRoom.py

40 lines
1.3 KiB
Python
Raw Normal View History

2019-10-04 22:00:47 +00:00
from app import db, ma
2019-10-09 23:27:41 +00:00
from marshmallow import fields
2019-10-11 00:41:49 +00:00
import enum
2019-10-09 05:53:37 +00:00
# TODO User >---< GameRoom
2019-10-02 03:14:21 +00:00
2019-10-11 00:41:49 +00:00
# ! Game Rooms >-< 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-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-11 00:41:49 +00:00
class Languages(enum.Enum):
EN = "English"
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-11 00:41:49 +00:00
language = db.Column(db.Enum(Languages), nullable=False, default=Languages.EN)
2019-10-02 03:14:21 +00:00
2019-10-11 00:41:49 +00:00
def __init__(self, name, description, private=False, language=Languages.EN):
2019-10-09 05:53:37 +00:00
self.name = name
self.description = description
self.private = private
self.language = language
2019-10-09 23:27:41 +00:00
class RoomSchema(ma.ModelSchema):
id = fields.Int()
name = fields.Str()
description = fields.Str()
private = fields.Bool()
2019-10-11 00:52:43 +00:00
language = fields.Str()
2019-10-09 23:27:41 +00:00
room_schema = RoomSchema()
rooms_schema = RoomSchema(many=True)