Giter Site home page Giter Site logo

Comments (4)

eamigo86 avatar eamigo86 commented on August 13, 2024

Hi @borsden, this seems a very good extension to make compatible but as I see it has no compatibility with Django> = 2.0 and that's not good? Do you have any information about it?

from graphene-django-extras.

borsdenold avatar borsdenold commented on August 13, 2024

I know about this issue (KristianOellegaard/django-hvad#344), but last action there was one year ago. Maybe you right, and it is not a good idea to try support legacy extension.
My previous idea with monkeypatching does not work, because i got something like this:
"Accessing translated fields like {model_name}.{field_name} from an regular model requires a translation-aware queryset, For regular, non-translatable models, you can get one using hvad.utils.get_translation_aware_manager". I tried several ways to solve it, but they all looks ugly.
So, i decided to stop on something like this

from graphene_django_extras import DjangoObjectType
from graphene_django_extras.converter import construct_fields
from graphene_django_extras.registry import get_global_registry


class DjangoHvadObjectType(DjangoObjectType):
    class Meta:
        abstract = True

    @classmethod
    def __init_subclass_with_meta__(
        cls,
        model=None,
        registry=None,
        only_fields=(),
        exclude_fields=(),
        **kwargs
    ):
        """Use this class for django-hvad models. Check, that it is TranslatableModel, then use model
        `model._meta.translations_model` as main model. Also manually resolve fields from main model.
        """
        assert hasattr(model._meta, 'translations_model'), (
            'You need to pass a TranslatableModel model (django-hvad) in {}.Meta, received "{}".'
        ).format(cls.__name__, model)
        translations_model = model._meta.translations_model

        if not registry:
            registry = get_global_registry()

        for name, field in construct_fields(model, registry, only_fields, ('id', 'translations') + exclude_fields).items():
            # Dynamic add resolvers for all fields from main model.
            def resolve_name(self, info, **kwargs):
                return getattr(self.master, name)

            setattr(cls, name, field)
            setattr(cls, 'resolve_{}'.format(name), resolve_name)

        super().__init_subclass_with_meta__(
            model=translations_model,
            registry=registry,
            only_fields=only_fields,
            exclude_fields=exclude_fields,
            **kwargs
        )

It also looks like my nightmare, but i don't want to continue touch it)

from graphene-django-extras.

borsdenold avatar borsdenold commented on August 13, 2024

Okey, finally i decide use django-parler insead of django-hvad, because it is too horrible)

from graphene-django-extras.

rapita avatar rapita commented on August 13, 2024

Hi @borsden
Please give your example of using django-graphene with django-parler

from graphene-django-extras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.