3
This is best enforced with Authorization.
You need to implement the delete_detail
method to return True or False, for example:
def delete_detail(self, object_list, bundle):
return bundle.obj.user == bundle.request.user
2
As explained in the tastyie cookbook. Maybe you can do something like this:
class DeleteComment(ModelResource):
def obj_delete(self, bundle, **kwargs):
# get post id
comment = Comment.objects.get(pk=bundle.data.id) # or or whatever way you can get the id
# delete all comments with that post id
Comment.objects.filter(post=comment.post).delete()
return super(DeleteComment, self).obj_delete(bundle, user=bundle.request.user)
def apply_authorization_limits(self, request, object_list):
return object_list.filter(user=request.user)
- [Django]-Django RadioSelect Choices From Model
- [Django]-Django reverse function arguments
- [Django]-How to run a series of manage.py commands in Django?
Source:stackexchange.com