Skip to content

Bridge Django field choices and graphene's enum type #3

Closed
@conradev

Description

@conradev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions