I have the following models:
class Poster(models.Model)
user = models.OneToOneField(User, primary=True)
userpicture = models.CharField(max_length =
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
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)