5

假设一个模型已经翻译了如下字段,我们如何使用 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)

...但这在这里行不通。有任何想法吗?

4

0 回答 0