Skip to content
Snippets Groups Projects

Add SuccessNextMixin for automatic redirecting after finishing an action

Merged Jonathan Weth requested to merge feature/success-next-mixin into master
All threads resolved!
+ 8
0
@@ -5,6 +5,7 @@ from typing import Any, Callable, List, Optional, Tuple, Union
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.views import LoginView, SuccessURLAllowedHostsMixin
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.managers import CurrentSiteManager
from django.contrib.sites.models import Site
@@ -415,6 +416,13 @@ class SuccessMessageMixin(ModelFormMixin):
return super().form_valid(form)
class SuccessNextMixin(SuccessURLAllowedHostsMixin):
redirect_field_name = "next"
def get_success_url(self) -> str:
return LoginView.get_redirect_url(self) or super().get_success_url()
class AdvancedCreateView(SuccessMessageMixin, CreateView):
pass
Loading