Flask 我如何对不同端点使用不同的转储函数?

Flask 我如何对不同端点使用不同的转储函数?,flask,serialization,deserialization,flask-restful,flask-marshmallow,Flask,Serialization,Deserialization,Flask Restful,Flask Marshmallow,我将flask_restful与flask_棉花糖一起使用,我想为不同的API序列化不同的对象 例如,当我想从api获取用户时,我有以下json: { "id": 2, "email": "aaaa", "notes": [ { "id": 3, "title": "This is

我将flask_restful与flask_棉花糖一起使用,我想为不同的API序列化不同的对象

例如,当我想从api获取用户时,我有以下json:

{
    "id": 2,
    "email": "aaaa",
    "notes": [
        {
            "id": 3,
            "title": "This is a title",
            "latitude": 25.546,
            "longitude": 30.6546,
            "time": 10000,
            "starting_time": "2021-05-18 22:45:49",
            "ending_time": "2021-05-19 01:32:29",
            "user_id": 2
        }
    ]
}
{
    "id": 2,
    "email": "aaaa"
}
但是,当我想要获得所有用户时,我只想要这个json:

{
    "id": 2,
    "email": "aaaa",
    "notes": [
        {
            "id": 3,
            "title": "This is a title",
            "latitude": 25.546,
            "longitude": 30.6546,
            "time": 10000,
            "starting_time": "2021-05-18 22:45:49",
            "ending_time": "2021-05-19 01:32:29",
            "user_id": 2
        }
    ]
}
{
    "id": 2,
    "email": "aaaa"
}
以下是我的模式:

class UserSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = UserModel
        ordered = True
        load_only = ('password',)
        dump_only = ('id', )
        load_instance = True

    notes = ma.Nested(NoteSchema(), many=True)

class NoteSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = NoteModel
        ordered = True
        dump_only = ('starting_time', 'ending_time',)
        load_instance = True
        include_fk = True