File tree 1 file changed +11
-1
lines changed
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1
1
"""Enumeration support for django model forms"""
2
2
3
+ import sys
3
4
from copy import copy
4
5
from decimal import DecimalException
5
6
from enum import Enum , Flag
@@ -103,7 +104,14 @@ def format_value(self, value):
103
104
# choice tuple to the string conversion of the value
104
105
# to determine selected options
105
106
if self .enum :
106
- return [str (en .value ) for en in self .enum (value )]
107
+ if sys .version_info < (3 , 11 ):
108
+ return [
109
+ str (flg .value )
110
+ for flg in self .enum
111
+ if flg in self .enum (value ) and flg is not self .enum (0 )
112
+ ]
113
+ else :
114
+ return [str (en .value ) for en in self .enum (value )]
107
115
if isinstance (value , int ):
108
116
# automagically work for IntFlags even if we weren't given the enum
109
117
return [
@@ -369,6 +377,8 @@ def __init__(
369
377
370
378
def _coerce (self , value : Any ) -> Any :
371
379
"""Combine the values into a single flag using |"""
380
+ if self .enum and isinstance (value , self .enum ):
381
+ return value
372
382
values = TypedMultipleChoiceField ._coerce (self , value ) # type: ignore[attr-defined]
373
383
if values :
374
384
return reduce (or_ , values )
You can’t perform that action at this time.
0 commit comments