[Answered ]-Django redirect to template passing model

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:

  1. Instead of supplying url as str object you called redirect which triggers redirect and skips the whole process of deletion.
  2. Make redirect to view with url argument supplying queryset and not str 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:

  1. 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])

Leave a comment