[Answer]-How to write helper method for PATCH request using django-tastypie?

1👍

Add the obj_update method in CommentResource: (assuming a uuid field)

def obj_update(self, bundle, **kwargs):
        old_text = bundle.obj.text
        new_text = bundle.data['text']
        Comment.objects.filter(uuid=bundle.data['uuid']).update(text=new_text) # update comment
        c = Comment.objects.get(uuid=bundle.data['uuid'])
        EditedComment(cmt=c, old_text = old_text, new_text = new_text).save()
        return bundle

Leave a comment