2👍
✅
Actually you still have object in .get_success_url()
,
From source code:
class DeletionMixin(object):
def delete(self, request, *args, **kwargs):
"""
Calls the delete() method on the fetched object and then
redirects to the success URL.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.object.delete()
return HttpResponseRedirect(success_url)
As you can see, firstly it computes success_url
and then it deletes the object.
What you did wrong:
- Instead of supplying url as
str
object you calledredirect
which triggers redirect and skips the whole process of deletion. - Make
redirect
to view with url argument supplyingqueryset
and notstr
as it has been waiting([a-z0-9]+)
I believe that in productlist
view you expect some sort of name of category, by which your products been filtered
So what you can do:
- Return valid
str
object in.get_success_url()
E.g.
class LampDelete(DeleteView):
model = Lamp
def get_success_url(self):
category = self.object.category
return reverse('productlist', args=[category])
Source:stackexchange.com