May 2018
Beginner to intermediate
526 pages
11h 57m
English
We have to adapt our shop views to use translation QuerySets. Run the following command to open the Python shell:
python manage.py shell
Let's take a look at how you can retrieve and query translation fields. To get the object with translatable fields translated in a specific language, you can use Django's activate() function as follows:
>>> from shop.models import Product>>> from django.utils.translation import activate>>> activate('es')>>> product=Product.objects.first()>>> product.name'Té verde'
Another way to do this is by using the language() manager provided by django-parler as follows:
>>> product=Product.objects.language('en').first()>>> product.name'Green tea'
When you access translated fields, they ...
Read now
Unlock full access