django-choices-field

This lib provides integration for enum resolution for Django’s TextChoices/IntegerChoices when defining the fields using the django-choices-field lib:

models.py
from django.db import models
from django_choices_field import TextChoicesField
class Status(models.TextChoices):
ACTIVE = "active", "Is Active"
INACTIVE = "inactive", "Inactive"
class Company(models.Model):
status = TextChoicesField(
choices_enum=Status,
default=Status.ACTIVE,
)
types.py
import strawberry
import strawberry_django
import .models
@strawberry_django.type(models.Company)
class Company:
status: strawberry.auto

The code above would generate the following schema:

schema.graphql
enum Status {
ACTIVE
INACTIVE
}
type Company {
status: Status
}
Edit this page on GitHub