Hi all,
I need to show a confirm message when the data is saves successfully
in the database.
My view function snippet is as following:
def itemSave(request, id=None, d={}):
if request.method == "POST":
if request.method == "POST" and form.is_valid():
if action == 'Save':
item = form.save(commit=False)
item.creator= request.user
try:
item.save()
d['saveMessage'] = "item Saved!"
except Exception:
d['saveMessage'] = "Error Occurred In Saving item.."
return HttpResponseRedirect("/item/%d" % item.id)
return render(request, 'createItem.html', d)
Template has:
{% if saveMessage %}
{{ saveMessage }}
{% endif %}
Now I want to stay on the same page (createItem) after save, which is
done bu calling return HttpResponseRedirect("/item/%d" % item.id) in
view code.
Therefore, the variable saveMessage retains its value and is displayed
in the page. But If I go to the createItem page by any other route,
say home>createITem, still this value persists, and even on empty new
form , I get to see "Item saved". If I reset the value of the var at
the begining of the view function, the value is always reset as it is
getting redirected to the same function.
How do I confirm a successfull/failed database insert call to the
user?
Thanks,
Sincerely,
Sonal.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---