Comments (4)
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.
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.
Okey, finally i decide use django-parler insead of django-hvad, because it is too horrible)
from graphene-django-extras.
Hi @borsden
Please give your example of using django-graphene with django-parler
from graphene-django-extras.
Related Issues (20)
- Dynamic Schema generation
- Travis rewrite to GitHub Actions HOT 2
- TODO
- Tried installing graphene-django-extras, but get errors about incompatibility HOT 3
- ImportError: cannot import name 'force_text' from 'django.utils.encoding' HOT 1
- Regarding UnionTypes
- Pagination Total Count HOT 7
- When using a model with a UUID Field as ID the update method does not provide a UUID Field HOT 1
- No type registered for model: <model>
- Getting duplicate results on a filter across multiple fields. Cannot add distinct.
- still maintained? HOT 5
- python error: can only concatenate list (not "tuple") to list in __init__.py
- Updates removing other fields if not supplied: Might not be specific to graphene-django-extras
- ImportError: cannot import name 'JSONField' from 'graphene_django.compat'
- AssertionError: Page value for PageGraphqlPagination must be a non-zero value
- Filtering on enum fields returns all results HOT 1
- Logs received not informative
- DjangoListObjectType BigInt Error
- Filter error HOT 2
- Pagination Total Count in DjangoFilterPaginateListField
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphene-django-extras.