[Answered ]-Using Django's CBV, how can I check if request.user == my_model.user?

2👍

My question seems to be a duplicate of Example of Django Class-Based DeleteView

This is how to do it:

def get_object(self, queryset=None):
    """ Hook to ensure object is owned by request.user. """
    obj = super(MyDeleteView, self).get_object()
    if not obj.owner == self.request.user:
        raise Http404
    return obj

Leave a comment