Does anyone know of or can anyone please produce a simple example of Django\'s class-based generic DeleteView? I want to subclass DeleteView and ensure that the currently lo
I would propose that the best (and simplest) way to do this would be to use the UserPassesTestMixin which gives you a cleaner separation of concerns.
Example:
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import DeleteView
class MyDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
def test_func(self):
""" Only let the user access this page if they own the object being deleted"""
return self.get_object().owner == self.request.user