mirror of
https://github.com/Llloooggg/TextSouls.git
synced 2026-03-06 12:36:23 +03:00
backend: добавили состояния персонажей
This commit is contained in:
41
backend/migrations/versions/4ab34de53087_.py
Normal file
41
backend/migrations/versions/4ab34de53087_.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 4ab34de53087
|
||||
Revises: 1da93403ba52
|
||||
Create Date: 2022-11-20 12:22:55.594622
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '4ab34de53087'
|
||||
down_revision = '1da93403ba52'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('character_states',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(length=255), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('name')
|
||||
)
|
||||
with op.batch_alter_table('characters', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('state_id', sa.Integer(), nullable=False))
|
||||
batch_op.create_foreign_key(None, 'character_states', ['state_id'], ['id'], ondelete='CASCADE')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('characters', schema=None) as batch_op:
|
||||
batch_op.drop_constraint(None, type_='foreignkey')
|
||||
batch_op.drop_column('state_id')
|
||||
|
||||
op.drop_table('character_states')
|
||||
# ### end Alembic commands ###
|
||||
@@ -62,5 +62,18 @@
|
||||
"wisdom_koef": 1.5
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"table_name": "character_states",
|
||||
"records": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Default"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Duel"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -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))
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user