File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 11"""Enumeration support for django model forms"""
22
3+ import sys
34from copy import copy
45from decimal import DecimalException
56from enum import Enum , Flag
@@ -103,7 +104,14 @@ def format_value(self, value):
103104 # choice tuple to the string conversion of the value
104105 # to determine selected options
105106 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 )]
107115 if isinstance (value , int ):
108116 # automagically work for IntFlags even if we weren't given the enum
109117 return [
@@ -369,6 +377,8 @@ def __init__(
369377
370378 def _coerce (self , value : Any ) -> Any :
371379 """Combine the values into a single flag using |"""
380+ if self .enum and isinstance (value , self .enum ):
381+ return value
372382 values = TypedMultipleChoiceField ._coerce (self , value ) # type: ignore[attr-defined]
373383 if values :
374384 return reduce (or_ , values )
You can’t perform that action at this time.
0 commit comments