From 8dd29be8bf8b3f915153bab0311b60f3ae058461 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sat, 25 Nov 2023 11:28:20 +0100 Subject: [PATCH] Add success message on object creation with link to object --- nummi/main/templates/main/base.html | 5 +++++ nummi/main/views.py | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/nummi/main/templates/main/base.html b/nummi/main/templates/main/base.html index 98da0b8..61de121 100644 --- a/nummi/main/templates/main/base.html +++ b/nummi/main/templates/main/base.html @@ -88,6 +88,11 @@ {% endspaceless %} {% endblock %}
+ {% if messages %} + + {% endif %} {% block body %}{% endblock %}
diff --git a/nummi/main/views.py b/nummi/main/views.py index 8095486..51a7131 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -1,8 +1,10 @@ from account.models import Account from category.models import Category +from django.contrib import messages from django.contrib.auth import views as auth_views from django.contrib.auth.mixins import LoginRequiredMixin from django.urls import reverse_lazy +from django.utils.html import format_html from django.views.generic import ( CreateView, DeleteView, @@ -55,7 +57,18 @@ class NummiCreateView(UserMixin, CreateView): return super().form_valid(form) def get_success_url(self): - return self.next or super().get_success_url() + surl = super().get_success_url() + messages.success( + self.request, + format_html( + "{name} {msg}", + surl=surl, + name=self.object, + msg="was created successfully", + ), + ) + + return self.next or surl class NummiUpdateView(UserMixin, UpdateView):