Skip to content

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
1
2
3
4
5
6
7
8
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
1
2
3
4
5
6
7
8
enum Status {
  ACTIVE
  INACTIVE
}

type Company {
  status: Status
}