From 248afdbaa1c4d4a6e16cc8323e26b9eebef30d65 Mon Sep 17 00:00:00 2001 From: "Terence D. Honles" Date: Tue, 29 Aug 2017 14:56:01 -0700 Subject: [PATCH 1/2] choices generated only if not provided and items are tuples Choices should conform to https://docs.djangoproject.com/en/1.11/ref/models/fields/#choices --- extras_mongoengine/fields.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extras_mongoengine/fields.py b/extras_mongoengine/fields.py index 5871ddf..7ce8264 100644 --- a/extras_mongoengine/fields.py +++ b/extras_mongoengine/fields.py @@ -75,7 +75,8 @@ class EnumField(object): def __init__(self, enum, *args, **kwargs): self.enum = enum - kwargs['choices'] = [choice for choice in enum] + if 'choices' not in kwargs: + kwargs['choices'] = [(c.value, c.name) for c in enum] super(EnumField, self).__init__(*args, **kwargs) def __get_value(self, enum): From c19be65c5bbd8ab9ea562c9d344b6e669b00923e Mon Sep 17 00:00:00 2001 From: "Terence D. Honles" Date: Thu, 31 Aug 2017 14:22:31 -0700 Subject: [PATCH 2/2] validate the underlying data type rather than the enum --- extras_mongoengine/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras_mongoengine/fields.py b/extras_mongoengine/fields.py index 7ce8264..67c2f7a 100644 --- a/extras_mongoengine/fields.py +++ b/extras_mongoengine/fields.py @@ -97,7 +97,7 @@ def validate(self, value): def _validate(self, value, **kwargs): return super(EnumField, self)._validate( - self.enum(self.__get_value(value)), **kwargs) + self.__get_value(value), **kwargs) class IntEnumField(EnumField, IntField):