5

I'm developing an API with Django Rest Framework, and I'd need some models with a few fields that should support translation in multiple languages then, of course, serializers should have to retrieve the field with the expected language. I've thought about two options: adding extra fields to the model (one field for language) or creating another model with all texts in every language. On the other hand, I've seen that there are some libraries such as django-modeltranslation that are intended to solve that issue, however, I'd like to know some opinions about them. What do you think? What would you recommend to me?

Thank you very much

FVod
  • 2,245
  • 5
  • 25
  • 52
  • 1
    I have the same problem. I'am currently investigation the option of using https://django-modeltranslation.readthedocs.io/en/latest/.. Maybe it could be useful – juanmiguelRua Oct 26 '19 at 22:00

1 Answers1

1

As per documentation,

Using in combination with django-rest-framework

When creating a new viewset , make sure to override get_queryset method, using queryset as a property won’t work because it is being evaluated once, before any language was set.

****

So depending on your needs you can create a class inheriting from drf (for example ViewSet), obtaining the language code from request and replacing the get_queryset method to filter by language.

mdargacz
  • 1,267
  • 18
  • 32