Skip to content

How can one pass model instances directly to a Schema without type errors ? #1282

Answered by vitalik
GTorreil asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @GTorreil

well I'm not a big fan of making EVERYTHING strictly typed... but in your case I guess you can do the following:

    cat = CatModel.objects.get(id=1)  # model_instance is of type MyModel
    cat_dto = CatDTO.from_orm(cat)
    return 200, CatCreateResponseDTO(cat=cat_dto, message="New cat created. 🐈")

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@GTorreil
Comment options

Answer selected by GTorreil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants