Add success message on object creation with link to object
This commit is contained in:
parent
76ac6bc7fb
commit
8dd29be8bf
2 changed files with 19 additions and 1 deletions
|
@ -88,6 +88,11 @@
|
||||||
{% endspaceless %}
|
{% endspaceless %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<main id="main">
|
<main id="main">
|
||||||
|
{% if messages %}
|
||||||
|
<ul>
|
||||||
|
{% for message in messages %}<li>{{ message }}</li>{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
{% block body %}{% endblock %}
|
{% block body %}{% endblock %}
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from account.models import Account
|
from account.models import Account
|
||||||
from category.models import Category
|
from category.models import Category
|
||||||
|
from django.contrib import messages
|
||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
from django.utils.html import format_html
|
||||||
from django.views.generic import (
|
from django.views.generic import (
|
||||||
CreateView,
|
CreateView,
|
||||||
DeleteView,
|
DeleteView,
|
||||||
|
@ -55,7 +57,18 @@ class NummiCreateView(UserMixin, CreateView):
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return self.next or super().get_success_url()
|
surl = super().get_success_url()
|
||||||
|
messages.success(
|
||||||
|
self.request,
|
||||||
|
format_html(
|
||||||
|
"<a href='{surl}'>{name}</a> {msg}",
|
||||||
|
surl=surl,
|
||||||
|
name=self.object,
|
||||||
|
msg="was created successfully",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.next or surl
|
||||||
|
|
||||||
|
|
||||||
class NummiUpdateView(UserMixin, UpdateView):
|
class NummiUpdateView(UserMixin, UpdateView):
|
||||||
|
|
Loading…
Reference in a new issue