wagtailtrans icon indicating copy to clipboard operation
wagtailtrans copied to clipboard

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

Open bruecksen opened this issue 6 years ago • 4 comments

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)

bruecksen avatar Apr 11 '18 15:04 bruecksen

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 avatar Apr 18 '18 09:04 Henk-JanVanHasselaar

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

bruecksen avatar Apr 18 '18 09:04 bruecksen

it's not working

kthehatter avatar Aug 31 '21 19:08 kthehatter

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

mwmdev avatar Jan 12 '24 18:01 mwmdev