Skip to content

Commit

Permalink
feat(api): add Organism schema and add it to User
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Vergez committed Dec 14, 2023
1 parent ee0c4da commit 842e3f8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/pypnusershub/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
from pypnusershub.db.models import User, Organisme


class OrganismeSchema(SmartRelationshipsMixin, ma.SQLAlchemyAutoSchema):
class Meta:
model = Organisme
load_instance = True
sqla_session = db.session


class UserSchema(SmartRelationshipsMixin, ma.SQLAlchemyAutoSchema):
class Meta:
model = User
Expand All @@ -19,17 +26,11 @@ class Meta:

nom_complet = fields.String()
groups = fields.Nested(lambda: UserSchema, many=True)
organisme = fields.Nested(OrganismeSchema)

# TODO: remove this and fix usage of the schema
@pre_load
def make_observer(self, data, **kwargs):
if isinstance(data, int):
return dict({"id_role": data})
return data


class OrganismeSchema(SmartRelationshipsMixin, ma.SQLAlchemyAutoSchema):
class Meta:
model = Organisme
load_instance = True
sqla_session = db.session

0 comments on commit 842e3f8

Please sign in to comment.