mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-05 12:53:12 +03:00
Allows field's choices to be a callable
Starting in Django 5 field's choices can also be a callable
This commit is contained in:
parent
96c09ac439
commit
a48abd1d33
|
@ -1,5 +1,6 @@
|
||||||
import inspect
|
import inspect
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from collections.abc import Callable
|
||||||
from functools import partial, singledispatch, wraps
|
from functools import partial, singledispatch, wraps
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -72,6 +73,8 @@ def convert_choice_name(name):
|
||||||
|
|
||||||
def get_choices(choices):
|
def get_choices(choices):
|
||||||
converted_names = []
|
converted_names = []
|
||||||
|
if isinstance(choices, Callable):
|
||||||
|
choices = choices()
|
||||||
if isinstance(choices, OrderedDict):
|
if isinstance(choices, OrderedDict):
|
||||||
choices = choices.items()
|
choices = choices.items()
|
||||||
for value, help_text in choices:
|
for value, help_text in choices:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user