backend: добавили состояния персонажей

This commit is contained in:
Leonid-Murzinov
2022-11-20 12:29:24 +03:00
parent 9c989350ec
commit 55f3cc7eff
5 changed files with 92 additions and 3 deletions

View File

@@ -8,8 +8,12 @@ from textsouls.models import User
from textsouls.models import CharacterRace
from textsouls.models import CharacterClass
from textsouls.models import CharacterState
from textsouls.models import Character
from textsouls.models import DuelParticipants
from textsouls.models import Duel
ts_admin = Blueprint("ts_admin", __name__)
@@ -30,4 +34,8 @@ admin.add_view(AdminView(User, db.session))
admin.add_view(CommonView(CharacterRace, db.session))
admin.add_view(CommonView(CharacterClass, db.session))
admin.add_view(CommonView(CharacterState, db.session))
admin.add_view(CommonView(Character, db.session))
admin.add_view(CommonView(DuelParticipants, db.session))
admin.add_view(CommonView(Duel, db.session))

View File

@@ -5,12 +5,21 @@ from textsouls.models import User
from textsouls.models import CharacterRace
from textsouls.models import CharacterClass
from textsouls.models import CharacterState
from textsouls.models import Character
from textsouls.models import DuelParticipants
from textsouls.models import Duel
main = Blueprint("main", __name__)
register_api(main, User, "users")
register_api(main, CharacterRace, "character_races")
register_api(main, CharacterClass, "character_classes")
register_api(main, CharacterState, "character_states")
register_api(main, Character, "characters", "owner")
register_api(main, DuelParticipants, "duels_participants")
register_api(main, Duel, "duels")

View File

@@ -66,6 +66,18 @@ class CharacterClass(db.Model, SerializerMixin):
return self.name
class CharacterState(db.Model, SerializerMixin):
__tablename__ = "character_states"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), nullable=False, unique=True)
characters = db.relationship("Character", backref="state", lazy="dynamic")
def __str__(self):
return self.name
class Character(db.Model, SerializerMixin):
__tablename__ = "characters"
@@ -96,6 +108,12 @@ class Character(db.Model, SerializerMixin):
agility_base = db.Column(db.Integer(), nullable=False, unique=False)
defence_base = db.Column(db.Integer(), nullable=False, unique=False)
wisdom_base = db.Column(db.Integer(), nullable=False, unique=False)
state_id = db.Column(
db.Integer,
db.ForeignKey("character_states.id", ondelete="CASCADE"),
nullable=False,
default=1,
)
def __init__(self, **kwargs):
super().__init__(**kwargs)
@@ -165,6 +183,9 @@ class DuelParticipants(db.Model, SerializerMixin):
db.ForeignKey("duels.id", ondelete="CASCADE"),
)
def __str__(self):
return self.duel_id, self.participant_id
class Duel(db.Model, SerializerMixin):
@@ -177,6 +198,3 @@ class Duel(db.Model, SerializerMixin):
participants = db.relationship(
"DuelParticipants", backref="duel", lazy="dynamic"
)
def __str__(self):
return self.name