question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DRF: Load only needed languages

See original GitHub issue

In 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:open
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
remychvncommented, Nov 14, 2019

duplicate of this issue: #484

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

0reactions
HotStewcommented, Jul 18, 2022

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 your fields attribute, as I did. That’s why it returns all of the translations.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found