DRF: Load only needed languages
See original GitHub issueIn combination with Django Rest Framework I noticed that all languages are included into the SQL query
"destinations_destination"."permalink",
"destinations_destination"."permalink_en",
"destinations_destination"."permalink_fr",
"destinations_destination"."permalink_de",
"destinations_destination"."permalink_es",
With many languages and many translated fields this can generate very heavy SQL queries. Is there a way to load only the desired language and the fallback language?
What would be the best way to implement this?
I guess this is a specific case for Django Rest Framework, but I think it might be interesting to discuss it here. I can’t be the only one using both together.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Serializer : Load only languages requested in headers #26
However, It is possible to load only languages requested in accept_language headers ? And maybe the default language if the str...
Read more >Different language settings for website and API - Stack Overflow
I have an application with two languages, Farsi and English. This application provides a website which uses Django templates and a simple API ......
Read more >Supporting Multiple Languages in Django | TestDriven.io
This tutorial looks at how to add multiple language support to your Django project.
Read more >What is Django Rest Framework and why you should learn it
DRF uses Python, a language easy to learn. Thanks to using Python and how DRF is structured, we only need a few lines...
Read more >Language · spaCy API Documentation
Keep in mind that this method only loads the serialized state and doesn't set up the nlp object. This means that it requires...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Indeed, it is 👍 I may try to implement this in a few weeks if I have some time Perhaps via a parameter in the modeltranslation configuration
I was thinking of maybe implementing some sort of a solution for this. I was looking at the the source code and it dawned on me that you can just specify the field without the suffix in the serializer
fields
attribute. It will then only return the original field with the translated value. I am assuming you have__all__
in yourfields
attribute, as I did. That’s why it returns all of the translations.