I have written a decorator to display success message on object creation:
from django.contrib import messages
def success_message(klass):
def form_valid(self, form):
response = super(klass, self).form_valid(form)
messages.success(self.request, 'Object added successfully')
return response
klass.form_valid = form_valid
return klass
and use it to decorate class based generic view:
@success_message
class BandCreateView(CreateView):
model = Band
Now I want to parameterize the decorator so this is possible:
@success_message('Band created successfully.')
class BandCreateView(CreateView):
model = Band
How do I do it? I tried adding message
parameter to success_message
but the compiler complained about parameter count mismatch so I figure there must be another way.