Skip to content

How to concatenate multiple fields into one in a Response Schema ? #1492

Closed Answered by simonpanay
simonpanay asked this question in Q&A
Discussion options

You must be logged in to vote

Finally found a solution here : https://docs.pydantic.dev/latest/concepts/fields/#exclude
The idea is to exclude those fields when "exporting" the schema

So in my example, the solution is :

class EpochSchema(Schema):
    code: str
    band_code: str = Field(exclude=True)
    instrument_code: str = Field(exclude=True)
    orientation_code: str = Field(exclude=True)

    @staticmethod
    def resolve_code(obj):
        return f"{obj.band_code}{obj.instrument_code}{obj.orientation_code}"

Sorry for the unnecessary noise

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by simonpanay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant