Reputation: 1918
I have a CreateView and an UpdateView with success messages in both. But, only the UpdateView success message works and the CreateView message isn't show. Why is this happening?
from django.contrib.messages.views import SuccessMessageMixin
class CreateRedirect (CreateView):
model = MarketingRedirect
template_name = 'marketing_redirect/create_redirect.html'
success_url = reverse_lazy('backend_redirect')
fields = ['redirect_from', 'redirect_to']
success_message = "Redirect successfully created!"
class EditRedirect(SuccessMessageMixin, UpdateView):
model = MarketingRedirect
fields = ['redirect_from', 'redirect_to']
template_name = 'marketing_redirect/edit_redirect.html'
context_object_name = 'redirect'
success_url = reverse_lazy('backend_redirect')
success_message = 'Review successfully updated'
Upvotes: 5
Views: 7169
Reputation: 2693
Inherit SuccessMessageMixin for class CreateRedirect as shown below:
class CreateRedirect(SuccessMessageMixin, CreateView):
....
Upvotes: 16