Skip to content

Support Enum for Select-field #267

@floqqi

Description

@floqqi

I have got some use cases where I use a Enum in my models.

Example:

# definitions.py
from enum import Enum

class Gender(Enum):
    male = 'm'
    female = 'f'
# models.py
from definitions import Gender

class Person:
    def __init__(self, gender: Gender):
        self.gender = gender

Now it would be great if I could use the Enum in marshmallow.fields.Select:

# schemas.py
from marshmallow import fields, Schema
from definitions import Gender
from models import Person

class PersonSchema(Schema):
    gender = fields.Select(Gender)

    @staticmethod
    def make_object(data) -> Person:
        return Person(**data)

For backwards-compatibility enum34 could be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions