Hi Tracy,
I have been working away on an inventory project and I have a need to delete ‘things’ as well as create and update. I know that you have a delete uploads ability in your hellowebapp project, but this is a bit different. I have tried altering the delete uploads code to suit but I cannot get it to work. (I will also be using the upload functionality as well).
I have tried for days now and despite trawling through google, I cannot find a workable solution and I keep getting all sorts of errors from the dreaded ‘no reverse found’ (I hate this error) to ‘item matching query does not exist’. The latter I believe is that the record has been deleted, but I don’t know what to do in code after this.
@login_required
def delete_item(request, id):
# grab the item
item = Item.objects.get(id=id)
# security check
#if item.thing.user != request.user:
#raise Http404
# delete the image
item2delete = item.delete()
# refresh the edit page
return render(request, 'items/edit_item.html', {'item': item, })
# return redirect('items/items.html') #, slug=item.slug)
Obviously, I am calling my ‘things’ as ‘items’ as in stock items.
In the above I also was going to use the return value of the item delete as this will be of some use.
The commented out return redirect does not work either but I kept it there so that I have something to work on.
Any assistance or pointers would be appreciated.
Kind regards
David