Skip to content

Customize enum choices in serializer #120

@MehdiDRISSIB

Description

@MehdiDRISSIB

Hello

Is that possible to restrict choices of enum class in serializer ?

This is my enum class:

class TransferType(Enum):
    Paypal = "PP"
    WesternUnion = "WU"
    Wallet = "WT"

    class Labels:
        Paypal = _('Paypal')
        WesternUnion = _('Western Union')
        Wallet = _('Wallet')

My serializer:

class TransferSerializer(EnumSupportSerializerMixin, serializers.ModelSerializer):
    wallet = serializers.SerializerMethodField(source='get_wallet')
    transfer_type = EnumField(enum=[TransferType.Paypal, TransferType.WesternUnion ])
    .......

I got this error when I post data:

isinstance() arg 2 must be a type or tuple of types

Exception Value: | isinstance() arg 2 must be a type or tuple of types
Exception Location: C:\Users\mehdi\PycharmProjects\venv\lib\site-packages\enumfields\drf\fields.py, line 35, in to_internal_value

Thank you

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