django-hvad

Django Rest Framework and Django-Hvad

久未见 提交于 2020-01-02 11:22:31
问题 so i needed to had some model-translation support for my DRF API and i started using django-hvad. It seems to work well with my django application but i am getting some issues with the DRF APi. I am trying to create a simple POST request and i am getting a error: Accessing a translated field requires that the instance has a translation loaded, or a valid translation in current language (en) loadable from the database Here are my models, serializers and viewsets: Model: class Mission

Translatable Manytomany fields in admin generate many queries

≡放荡痞女 提交于 2019-12-06 04:46:23
问题 I am using django-parler (a derivative of django-hvad) for translations. In admin when displaying Foreignkey fields with manytomany relationship, django runs a single query for each: So when there are 300 services there would be as many queries. I think the prefetch_related on get_queryset doesn't apply to mantomany filters/lists, correct me if I am wrong: def get_queryset(self, request): return super(DoctorAdmin, self).get_queryset(request).prefetch_related('translations', 'services_

Translatable Manytomany fields in admin generate many queries

怎甘沉沦 提交于 2019-12-04 09:55:01
I am using django-parler (a derivative of django-hvad) for translations. In admin when displaying Foreignkey fields with manytomany relationship, django runs a single query for each: So when there are 300 services there would be as many queries. I think the prefetch_related on get_queryset doesn't apply to mantomany filters/lists, correct me if I am wrong: def get_queryset(self, request): return super(DoctorAdmin, self).get_queryset(request).prefetch_related('translations', 'services__translations') has no effect on number of queries. Enabling caching on parler (as the author suggested here )