[Python] Extend Marshmallow Schema but Override Field Required Property

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024.

  1. Stack

    Stack Membro Participativo

    Noob question, but I have a simple schema:

    class User(Schema):
    name = fields.Str(required=True)
    email = fields.Str(required=True)


    And I want to extend it, but in the extended case make a field optional

    class UserIHavePhoneNumberFor(User):
    phone = fields.Str(required=True)
    # Don't Care about Email because I can pester them via phone!


    I've checked the docs but can't find a way to do this. Any help?

    Thank you!

    Continue reading...

Compartilhe esta Página