autodoc_pydantic: Show fields from parent model

Daniel Walker

I'm using the autodoc_pydantic plugin for Sphinx to document my pydantic.BaseModel classes. However, there are cases where I have something like

class Foo(pydantic.BaseModel):
    '''Foo class'''

    x: str = pydantic.Field(description='The x.')

class Bar(Foo):
    '''Bar class'''

    y: int = pydantic.Field(description='The y.')

My .rst file contains the directive

.. automodule:: foo.foo
    :members:

When the documentation is generated, only the y field is shown for the Bar class. Is there a way to get autodoc_pydantic to show both x and y in Bar's description?

Daniel Walker

It can be accomplished via the :inherited-members: option:

.. automodule:: foo.foo
    :inherited-members: BaseModel

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Show model parent fields in Django's admin model details

How to access a parent model from one of my fk fields?

Django admin add form show object fields from related model

How to show all fields values of a model from a form in Django?

Interdependent Validation for Pydantic Model Fields

Passing fields from parent view model to child (partial) view MVC + Razor

How to extract certain db fields from a parent model using STI in Rails

update only from's visible fields if parent model doesn't exist

Django: store common fields in a parent model

Django: how to show related model fields in template

Individually specify nested dict fields in pydantic model

Return Pydantic model as None if all fields are None

django model with two fields from another model

Pydantic how to create a model with required fields and dynamic fields?

Laravel - Extend Model $guarded from parent model

Overwrite parent model attribute from child model

form_for a "belongs_to" model in 'show' of parent model

Show information from a model and save it in and other model

Show fields from MySQL DB from Search

Laravel Nova - Show/Hide form fields based on a parent Select field

pydantic generate model from dict

How to access private fields from parent class

How to remove fields from parent form?

Access all fields from parent method

Jackson is ignoring all fields from parent

Generate a pydantic model from pydantic object

Django unique_together on model parent class fields

active_record-acts_as - validate parent fields on child model

Backpack CRUD Controller: show fields depending on model is editing