Django REST Framework as backend for tracking user history

Viewed 448

I'm trying to track user history using a DRF backend. For that, I've created a history table that will get a new timestamped row with each update. This model is a many-to-one and has a reference to the user model by a foreign key.

Here comes the confusing part. Every time I pull up the user profile, I would like to also pull the last entry into the history table. Thus, I am considering adding a couple of columns in the table which get updated with every insert into the history table since this is probably less expensive than performing a secondary lookup each time. I'd like some feedback on this approach.

Additionally, I'm slightly confused by how to perform this update/insert combination via a single API endpoint as DRF seems to only support one-to-one CRUD.

For illustrative purposes, I'd like to achieve the following via a single API view:

User hits API endpoint with access token and update values --> Insert history table --> update user table for user's row with inserted details

Thanks!

0 Answers
Related