I have created a form to delete objects but I need to check that the user that want to delete the object is the user who created that object. I would like to check it in the form (as well as in the view) as it is a business constraint. Where is the best place to check that, in the init, delete or clean method?
class DeleteFooForm(forms.ModelForm):
class Meta:
model = Foo
fields = []
def __init__(self, user, *args, **kwargs):
super(DeleteFooForm, self).__init__(*args, **kwargs)
self.user = user
def delete(self):
if self.user is not self.instance.user:
raise PermissionDenied("Wrong user")
self.instance.delete()
# more actions, send email, etc.