Garfonzo
Garfonzo

Reputation: 3966

Django - deleting a model instance - what am I doing wrong?

I have a simple Delete function to drop scheduled events. Here's the function:

def delete_sch_item(request, scPK):
    redirect_to = request.REQUEST.get('next', '')
    s = Schedule_Item.objects.get(pk=scPK)
    s.delete()
    return HttpResponseRedirect(redirect_to)

Every time I call this view by way of a url, it ALWAYS returns the error:

DoesNotExist at /schedule/delete-event/60/
Schedule_Item matching query does not exist.

Even though I look at the raw database and see that, yes, that item does exist. Even more confusing is that when I go back to viewing my list of scheduled items, the one that appearantly "Does Not Exist" has, in fact, been deleted.

What's going on?!

Upvotes: 0

Views: 167

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799390

For some reason your view is being called twice. The first call deletes the object, and the second call throws the exception.

Upvotes: 3

Related Questions