I have a site that I've structured like so:
Top Page: Animals
Subpage: Cat
Subpage: Dog
Top Page: Cat
Subpage: Food
Top Page: Dog
Subpage: Food
That way, a user can go to site/animals or site/cat. Animals is high-level info, Cat and Dog are more detailed parts of the site.
What I want to do:
Occasionally, I want to be able to reuse pages from Animals and use them in Cat or Dog. But I don't want the url to switch from one section to another.
Example: If the user is under Animal, and they click a food article, the url should be:
animals/cats/food_article
If they click on that same article under cats, the url should look like:
cats/food_article
What I've tried:
I've tried using RoutableRouteMixin
. But that works for subpages, not for pages at the same level.
I tried overwriting the get_url_parts
method for the article models. But then I got 404 errors because the pages didn't actually exist at the url I created.
Can this be achieved in Wagtail? Or is there a Django solution I can use with Wagtail?
Potential Approach
get_children
method which is on eachPage
and comes fromdjango-treebeard
. This method is used by the routing logic to determine if a page is a child of another (when a URL is read).AnimalPage
s, then create anArticlePage
(e.g. Food Article), then go into the dog page AND cat page and link the food article to the page.http://localhost:8000/food-article/
,http://localhost:8000/animals/cats/food-article/
andhttp://localhost:8000/animals/dogs/food-article/
.ArticlePage
s under their own parent page and then use routablemixin to make that page not show any sub-urls.ArticlesPage
, this should still work as it only checks the 'last' section of the URL). I have not tested this though.Example Code