Wagtail: Redirect after saving site setting

I'm trying to redirect the user to a custom HTML page after saving a BaseSiteSetting model in Wagtail 4.1.1

I'm not sure how to accomplish this, the BaseSiteSetting inherits from django models.Model which means it's possible to override the save() function but how would I do the actual redirect without having access to the request?

Another acceptable solution would be to add an extra button in the CMS by overriding the default BaseSiteSetting HTML template but I can't seem to get that working either, except for ModelAdmin templates. I've opened a stackoverflow question about that here.

My view with the custom HTML page:

def sync(request):
    return render(request, "import.html", {"WS_PROTOCOL": settings.WS_PROTOCOL})

My BaseSiteSetting model:

class AnonymousSuccessStoryImportSetting(BaseSiteSetting):
    Setting for importing anonymous success stories.

    file = models.FileField(
        help_text="Upload a CSV file, then click 'Save' afterwards",
    date = models.DateTimeField(auto_now_add=True)

    class Meta:
        verbose_name = "Importer"

I've looked around for possible solutions, and found some wagtail hooks but these only apply to the Wagtail Page model, for example: after_publish_page.

It's unfortunate that there's no hook for standard django models.

It looks to me like BaseSiteSettings is one of the models that has not been converted to use class-based views. So I think you need to monkey patch this edit method to change the 'after save' redirect here: https://github.com/wagtail/wagtail/blob/main/wagtail/contrib/settings/views.py#L121

Back to Top