def delete request id poll Polls objects get id id if Polls objects fi

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def delete(request, id):
poll = Polls.objects.get(id=id)
if Polls.objects.filter(id=id).count() < 1 or poll.user != request.user:
return HttpResponseRedirect('/')
else:
comments = Comments.objects.filter(poll=poll)
comments.delete()
options_votes = OptionsVotes.objects.filter(poll=poll)
options_votes.delete()
options = Options.objects.filter(poll=poll)
options.delete()
poll.delete()
return HttpResponseRedirect('/')