wagtailtrans
wagtailtrans copied to clipboard
Documentation: Add an example how to query all pages of the current language
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)
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?
@Henk-JanVanHasselaar yes lets do it. Will try to do something the next days!
it's not working
Also looking for a simple example on how to do this.