Skip to content

Commit

Permalink
Allows field's choices to be a callable
Browse files Browse the repository at this point in the history
Starting in Django 5 field's choices can also be a callable
  • Loading branch information
nossila authored Feb 7, 2024
1 parent 96c09ac commit a48abd1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions graphene_django/converter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inspect
from collections import OrderedDict
from collections.abc import Callable
from functools import partial, singledispatch, wraps

from django.db import models
Expand Down Expand Up @@ -72,6 +73,8 @@ def convert_choice_name(name):

def get_choices(choices):
converted_names = []
if isinstance(choices, Callable):
choices = choices()
if isinstance(choices, OrderedDict):
choices = choices.items()
for value, help_text in choices:
Expand Down

0 comments on commit a48abd1

Please sign in to comment.