generateur_v3/backend/api/schemas/exercices.py

33 lines
1.3 KiB
Python
Raw Normal View History

2022-09-16 21:50:55 +02:00
from tortoise.contrib.pydantic import pydantic_model_creator
from services.schema import as_form
from database.exercices.models import Exercice, Tag
from pydantic import BaseModel
Exercice_schema = pydantic_model_creator(Exercice, name="Exercice", exclude=['tags.owner','author.clientId', 'created_at', 'updated_at'])
ExerciceIn_schema = pydantic_model_creator(
Exercice, name="ExerciceIn", exclude_readonly=True, exclude=['id_code', 'exo_source', "tags_id", 'author_id', 'origin'])
Exercices_schema = pydantic_model_creator(Exercice, name="exercices", include=[
'name', 'id_code', 'tags'], exclude=['tags.owner'])
Exercices_withoutTags = pydantic_model_creator(Exercice, name = 'exercices_wTags', include=['name', 'id_code'])
@as_form
class ExerciceIn_form(ExerciceIn_schema):
pass
class ExerciceSchema(Exercice_schema):
is_author: bool
exo_source_name: str
Tag_schema = pydantic_model_creator(Tag, name="tag", include=['label', "id_code", "color"])
TagFull_schema = pydantic_model_creator(Tag, name='tagFull', exclude=['owner', 'exercices'])
TagIn_schema = pydantic_model_creator(
Tag, name="tagIn", exclude_readonly=True, include=['label', 'id_code', 'color'])
class TagIn(BaseModel):
label: str
id_code: str
color: str