Fix when selecting with an MSFList
This commit is contained in:
parent
07a5e442b2
commit
6b7b4ea48d
|
@ -14,8 +14,13 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this programe. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from collections import UserList
|
||||
from typing import Optional, Union
|
||||
|
||||
from django.db.models.sql.query import Query
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
string = basestring # noqa: F821
|
||||
|
@ -25,6 +30,16 @@ else:
|
|||
string_type = string
|
||||
|
||||
|
||||
class _FakeSqlVal(UserList):
|
||||
|
||||
contains_aggregate = False
|
||||
contains_column_references = False
|
||||
contains_over_clause = False
|
||||
|
||||
def __str__(self):
|
||||
return ','.join(map(str, self))
|
||||
|
||||
|
||||
class MSFList(list):
|
||||
|
||||
def __init__(self, choices, *args, **kwargs):
|
||||
|
@ -35,6 +50,16 @@ class MSFList(list):
|
|||
msg_list = [msgl.choices.get(int(i)) if i.isdigit() else msgl.choices.get(i) for i in msgl]
|
||||
return u', '.join([string_type(s) for s in msg_list])
|
||||
|
||||
def resolve_expression(
|
||||
self, query: Query = None, allow_joins: bool = True,
|
||||
reuse: Optional[bool] = None, summarize: bool = False,
|
||||
for_save: bool = False) -> Union[list, _FakeSqlVal]:
|
||||
if for_save:
|
||||
result = _FakeSqlVal(self)
|
||||
else:
|
||||
result = list(self)
|
||||
return result
|
||||
|
||||
if sys.version_info < (3,):
|
||||
def __unicode__(self, msgl):
|
||||
return self.__str__(msgl)
|
||||
|
|
Loading…
Reference in New Issue