Closed
Description
I have a model that looks something like this:
class Organisation(models.Model):
CATEGORY_CHOICES = (
(1, _('Government administrative authorities')),
(2, _('Authorities under parliament')),
(3, _('State utilities')),
(4, _('AP fonds')),
(5, _('Courts of Sweden and courts administration')),
(6, _('Swedish foreign authorities')),
)
category = models.IntegerField(_('category'),
choices=CATEGORY_CHOICES
)
The import part is that category is a choice that has a translation (which is in Swedish btw).
When I query for this field I get this (as an example):
"category": "STATLIGA_F_RVALTNINGSMYNDIGHETER"
...which looks pretty weird to me.
The schema looks like this:
class OrganisationNode(DjangoObjectType):
class Meta:
model = Organisation
interfaces = (graphene.Node,)
If I instead do this:
class OrganisationNode(DjangoObjectType):
category = graphene.String()
class Meta:
model = Organisation
interfaces = (graphene.Node,)
def resolve_category(self, args, context, info):
return self.get_category_display()
...the result is as expected, e.g.:
"category": "Statliga förvaltningsmyndigheter"
So, there is a way around it. I was just wondering if this is by design or...??
Metadata
Metadata
Assignees
Labels
No labels