I want to log all CRUD operations performed on Django Model Objects via REST framework implemented in django rest framework. I extend viewsets.ModelViewSet to create my custom viewSet class for defining REST API end points.
1 Answer
There can be two different solutions...
1.Use signals in django to keep track of each operation in CRUD and make different model whose instance is created for each signal.Something like this....
signals.py
@receiver(post_save, sender= Sender_model)
def crud_log(sender,created,**kwargs):
obj= kwargs.get('instance')
recipient=User.objects.get()
Notification.objects.create(
recipient= recipient,
comment= obj,
send_by=obj.supporter,
text= "%s has commented on %s" % (obj.supporter,obj.project)
)
return None
here Notification is a model made by you to keep log of changes.
2.another solution is to use django-simple-history.