Saturday, August 31, 2013

verify before make changes?

def delete_item(request, item_id):
item = get_object_or_404(Item, pk=item_id)
return render(request, 'delete_item.html', {'item':item, 'item_id':item_id},)

def delete_confirmed(request, item_id):
query = get_object_or_404(Item, pk=item_id)
query.delete()
return render(request, 'delete_success.html', {'query':query},)

I came up with these functions that delete an object from the db after a user confirmation. However, these do not check if the object actually exist and or already deleted.

How do I make these functions to verify before making any hits or changes to db?

Likewise, I will derive the understanding from it and apply to my save function, in order that I might avoid duplication of items in my db.

I'm using modelforms for the save form though

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment