[Python] pydantic exclude multiple fields from model

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    In pydantic is there a cleaner way to exclude multiple fields from the model, something like:


    class User(UserBase):
    class Config:
    exclude = ['user_id', 'some_other_field']



    I am aware that following works.


    class User(UserBase):

    class Config:
    fields = {'user_id': {'exclude':True},
    'some_other_field': {'exclude':True}
    }


    but I was looking for something cleaner like django rest framework, where you could just specify a list of exclude or include per.

    Continue reading...

Compartilhe esta Página