Skip to content

Integration with django-polymorphic? #365

Answered by vitalik
furious-luke asked this question in Q&A
Discussion options

You must be logged in to vote

@furious-luke

OpenAPI forces you to describe all fields that you willing to output - so you would need to create union of all child models:

something like this:

class ManagerSchema(ModelSchema):
    class Config:
        model = Manager
        model_fields = '__all__'

class EmployeeSchema(ModelSchema):
    class Config:
        model = Employee
        model_fields = '__all__'


@api.get('/people', response=List[Union[ManagerSchema, EmployeeSchema]]) # !!!
def list_people(request):
    return Person.objects.all()

let me know if this works

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@furious-luke
Comment options

Comment options

You must be logged in to vote
1 reply
@furious-luke
Comment options

Answer selected by furious-luke
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