Bridge Django field choices and graphene's enum type
See original GitHub issueIt would be awesome to see something like this:
class Foo(models.Model):
TWITTER = 'twitter'
WEBSITE = 'website'
FULL_NAME = 'full_name'
IDENTITY_CHOICES = (
(TWITTER, 'Twitter'),
(WEBSITE, 'Website'),
(FULL_NAME, 'Full Name'),
)
main_identity = models.CharField(max_length=10, choices=IDENTITY_CHOICES, default=FULL_NAME)
turned into something like this:
class Identity(graphene.Enum):
TWITTER = Foo.TWITTER
WEBSITE = Foo.WEBSITE
FULL_NAME = Foo.FULL_NAME
class FooType(DjangoObjectType):
main_identity = graphene.NonNull(Identity)
class Meta:
model = Foo
automatically. I will work on this if I have time to implement it.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to use enums as a choice field in django model
But here is an answer to "a" question: Django will unfortunately never return an enum type, and always return a string. So foo.state...
Read more >Introducing an Enum choice field for Django
We created a small Django package that introduces an EnumChoiceField – a layer on top of CharField + choices, that uses Python's enums....
Read more >Django Graphene Multiple Schema
The implementation creates a enum from doing field definition. Given review of django ... Staleness will be parameterized if django graphene multiple schema....
Read more >Flutter Login app with Python Backend
We'll show you how to use Flutter and Python to build a flutter login app by connecting a Python backend and a Flutter...
Read more >Enums
It's possible to add a description to an enum value, for that the enum value needs to have the description property on it....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
What we need is some mechanism to override the choice -> Enum mapping for a Django choice field.
Cleaning up old resolved PRs.
The basic functionality for this is working in master. If there are any unresolved bugs or specific related features, please open a new issue.