I have following tables:
Contributor:
- id
- user_id
- project_id
User:
- id
- full_name
- username
Project:
- id
- name
and I need to get list of all contributors in given project:
what i have so far in my endpoint code:
contributors = session.query(Contributor).filter_by(project_id=project_id).all()
return to_json(contributors)
implementation of to_json method:
def to_json(result: Any) -> str:
return flask.jsonify(_convert_models(result))
and json method in Contributor model:
def __json__(self):
return ('id', 'user_id', 'project_id')
this would give me following response:
[
{
"id": 1,
"project_id": 1,
"user_id": 1
},
{
"id": 2,
"project_id": 1,
"user_id": 2
}
]
what I need is something like that:
[
{
"id": 1,
"project_id": 1,
"user": {
"id": 1,
"full_name": "Darth Vader",
}
},
...
]