假设一个模型已翻译如下所示的字段,我们如何用django-graphene查询这些?
from parler.models import TranslatableModel, TranslatedFields
class Article(TranslatableModel):
#regular fields
publishing_date = models.DateTimeField(_('publishing date'),
default=now)
# translated fields
translations = TranslatedFields(
title=models.CharField(_('title'), max_length=234),
slug=models.SlugField(
verbose_name=_('slug'),
max_length=255,
db_index=True,
blank=True,
),
meta_title=models.CharField(
max_length=255, verbose_name=_('meta title'),
blank=True, default=''),
meta_description=models.TextField(
verbose_name=_('meta description'), blank=True, default=''),
meta_keywords=models.TextField(
verbose_name=_('meta keywords'), blank=True, default=''),
)
对于注册“未知”字段,我会执行以下操作:
@convert_django_field.register(GeopositionField)
def convert_geofield_to_string(field, registry=None):
return graphene.String(description=field.help_text, required=not field.null)
...但这不适用于此。有什么想法吗?