How to Log Old and New Data on Model Updates in Django Rest Framework Using Celery for Asynchronous Processing?
I need to log both the old and new values of fields whenever a model is updated in Django Rest Framework (DRF). The logs should be saved in a separate database or an external system like Elasticsearch. The challenge is to capture both values without querying the database again and without affecting performance. I want to handle this logging process asynchronously using Celery.
What I Tried:
- Used pre_save and post_save signals to detect updates.
- Tried querying the database to get the old data, but I want to avoid this extra query.
- Integrated Celery to handle the logging asynchronously, but not sure about the best way to capture the old and new values efficiently.
What I Need Help With:
- How can I capture both old and new data without querying the database?
- How can I use Celery to handle logging asynchronously to avoid performance issues?
- Is there an existing pattern or best practice for logging changes in Django models?