I’ve custom CBV delete view which should check object‘s owner against request.user.
What is the good practice to do it?
Currently I’ve been checking as shown below
equal_usernames = some_object.user.username in request.user.username
equal_emails = some_object.user.email in request.user.email
if equal_usernames and equal_emails:
# some actions
Sultan
As simple as:
Because Model as
__eq__defined as such:So it’s “equal” as long as it’s the same model class with the same pk.