question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bridge Django field choices and graphene's enum type

See original GitHub issue

It 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
yen223commented, Oct 18, 2016

What we need is some mechanism to override the choice -> Enum mapping for a Django choice field.

0reactions
spockNinjacommented, Sep 8, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found