Skip to content

Instantly share code, notes, and snippets.

@Kniyl
Created July 7, 2015 15:46
Show Gist options
  • Save Kniyl/44acedbb7de112214132 to your computer and use it in GitHub Desktop.
Save Kniyl/44acedbb7de112214132 to your computer and use it in GitHub Desktop.
Proxy model
class Proxy(Page):
"""
A general content type for creating links to existing pages
in the page menu. Act as a placeholder for the first child
page if no page is explicitely being proxied.
"""
target = models.ForeignKey("Page", related_name="proxies", blank=True, null=True)
class Meta:
verbose_name = _("Proxy page")
verbose_name_plural = _("Proxies pages")
@processor_for(Proxy)
def proxy_processor(request, page):
"""
Redirect to the proxied page. If none exist, try
to redirect to the first child page.
"""
target = page.proxy.target
if target:
return redirect(target)
target = list(page.children.published().order_by('_order')[:1])
if target:
return redirect(target[0])
raise Http404
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment