I have a view that handles a variety of forms to manage objects (e.g rename, delete, etc.). For each action I want to define a success and error message such that I do not need to have the message text written directly in the view. Rather I want to do something like this:
CURRENT
def manage(request):
...
if form.is_valid():
...
messages.success(request, 'Instance rename successful')
else:
messages.error(request, 'Instance rename failed')
WHAT I WANT
def manage(request):
...
if form.is_valid():
...
add_message(request, messages.success.rename)
else:
add_message(request, messages.error.rename)
This is a simple example but I would have more complex messages that I would like to abstract out of the view and simply reference them as shown in the second example.
Any thoughts on how I can accomplish this?