5

Assuming a model that has translated fields like below, how can we query these with 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=''),
    )

For registering "unknown" fields I do something like:

@convert_django_field.register(GeopositionField)
def convert_geofield_to_string(field, registry=None):
     return graphene.String(description=field.help_text, required=not field.null)

... but this won't work here. Any ideas?

fekioh
  • 894
  • 2
  • 9
  • 22
  • I wonder if you have found a way of solving this. I'm currently facing the same issue and have a workaround of manually defining each of the `TranslatedFields` as extra fields in the `DjangoObjectType`. This is of course not scalable and misses the point of using a model as a node. – edwillys May 02 '21 at 09:06
  • I submitted a ticket to graphene-django. Issue can be tracked [here](https://github.com/graphql-python/graphene-django/issues/1195) – edwillys May 02 '21 at 11:38

0 Answers0