fix: Fix broke 'get_choices' with restframework 3.15.0 (#1506)

This commit is contained in:
Diogo Silva 2024-03-18 01:58:47 +00:00 committed by GitHub
parent 54372b41d5
commit ac09cd2967
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,4 @@
import inspect import inspect
from collections import OrderedDict
from functools import partial, singledispatch, wraps from functools import partial, singledispatch, wraps
from django.db import models from django.db import models
@ -72,8 +71,13 @@ def convert_choice_name(name):
def get_choices(choices): def get_choices(choices):
converted_names = [] converted_names = []
if isinstance(choices, OrderedDict):
# In restframework==3.15.0, choices are not passed
# as OrderedDict anymore, so it's safer to check
# for a dict
if isinstance(choices, dict):
choices = choices.items() choices = choices.items()
for value, help_text in choices: for value, help_text in choices:
if isinstance(help_text, (tuple, list)): if isinstance(help_text, (tuple, list)):
yield from get_choices(help_text) yield from get_choices(help_text)