I have a model with fields:
aseet_code
d1:
d2:
user:
etc.:
I want to put delete action filter on admin site ,so that logged in user can delete only if user field data and current logged in user is same.
user==current_logged_in_user
Otherwise it should raise exception like "This is not your data!".
Take a look at the has_delete_permission method in ModelAdmin. It sounds like all you would need to do is override that:
def has_delete_permission(self, request, obj = None):
if request.user == obj.user:
return True
return False
I have a model with fields:
aseet_code
d1:
d2:
user:
etc.:
I want to put delete action filter on admin site ,so that logged in user can delete only if user field data and current logged in user is same.
user==current_logged_in_user
Otherwise it should raise exception like "This is not your data!".
Take a look at the has_delete_permission method in ModelAdmin. It sounds like all you would need to do is override that:
def has_delete_permission(self, request, obj = None):
if request.user == obj.user:
return True
return False
0 commentaires:
Enregistrer un commentaire