0

I am trying to create a custom slug for every page of a specific Page model on Wagtail. I have been looking into and tried the RoutablePageMixin examples, but that seems to modify the url structure, not the slug itself.

Here is what I am looking to do:

Current page title: About Django

current page slug: about-django

page title I want: About Django

page slug I want: awesome-things-about-django

I looked at creating route method, but that didn't seem to modify the slug. Is there any way to prepend something onto your slug? I understand I can do this manually, but would prefer for it to happen automatically.

1 Answers1

1

One possibility for making automatic updates to pages on save is to override the full_clean method:

class MyPage(Page):

    # ...

    def full_clean(self, *args, **kwargs):
        # first call the built-in cleanups (including default slug generation)
        super(MyPage, self).full_clean(*args, **kwargs)

        # now make your additional modifications
        if not self.slug.startswith('awesome'):
            self.slug = "awesome-%s" % self.slug
gasman
  • 23,691
  • 1
  • 38
  • 56