wagtail / wagtailtrans

A Wagtail add-on for supporting multilingual sites
http://wagtailtrans.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
104 stars 60 forks source link

Documentation: Add an example how to query all pages of the current language #123

Open bruecksen opened 6 years ago

bruecksen commented 6 years ago

It would be nice to have an example in the documentation on how to query pages for specific languages or the current language. This is something you need to do for example to render the site menu. I did it like this in a function where you have the request context. Maybe there is a better way?

language = request.LANGUAGE_CODE
root_page = request.site.root_page
candidates = TranslatablePage.objects.live().specific().child_of(root_page)
pages = candidates.filter(language__code=language)
Henk-JanVanHasselaar commented 6 years ago

Hi @bruecksen , This could indeed be nice to have. In theory querying pages from one specific language can be done exactly as you describe it, you could even make it more concise by filtering like this:

pages = TranslatablePage.objects.live().filter(language__code=language).specific().child_of(root_page)

or you could even query on the path.

pages = TranslatablePage.objects.live().filter(language__code=language, path__startswith=root_page.path).specific()

We could make a tips & examples page in the documentation where these kind of little helpers can be defined.

Would you like to make a start with this page?

bruecksen commented 6 years ago

@Henk-JanVanHasselaar yes lets do it. Will try to do something the next days!

kthehatter commented 3 years ago

it's not working

mwmdev commented 8 months ago

Also looking for a simple example on how to do this.