Skip to content

Commit

Permalink
Merge pull request #10 from IAmNatch/feature-convert-clusterTaggableM…
Browse files Browse the repository at this point in the history
…anager

add conversion for ClusterTaggableManager
  • Loading branch information
tr11 authored Jun 10, 2020
2 parents 2b38469 + 0e12d99 commit 1c10172
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion wagtail_graphql/types/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from graphene_django.converter import convert_django_field, String, List
# wagtail
from wagtail.core.models import Page as wagtailPage, Site as wagtailSite
from taggit.managers import TaggableManager
from taggit.managers import TaggableManager,
from modelcluster.tags import ClusterTaggableManager
from wagtail.core.utils import camelcase_to_underscore
# app
from ..settings import url_prefix_for_site, RELAY
Expand Down Expand Up @@ -90,6 +91,22 @@ def resolve_children(self, info: ResolveInfo, **_kwargs):
).live().order_by('path').all()


# https://jossingram.wordpress.com/2018/04/19/wagtail-and-graphql/
class FlatTags(graphene.String):

@classmethod
def serialize(cls, value):
tagsList = []
for tag in value.all():
tagsList.append(tag.name)
return tagsList

@convert_django_field.register(ClusterTaggableManager)
def convert_tag_field_to_string(field, registry=None):
return graphene.Field(FlatTags,
description=field.help_text,
required=not field.null)

@convert_django_field.register(TaggableManager)
def convert_field_to_string(field, _registry=None):
return List(String, description=field.help_text, required=not field.null)
Expand Down

0 comments on commit 1c10172

Please sign in to comment.