7

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 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.