Rerun calculations and update db after db change

Hello all,

I’ve got an app that accepts csv files, runs a couple of pandas operations including some calculations and end up with three pd.DataFrames that I push to my database.

Now, sometimes there will be the need to edit some entries (currently only via the admin panel) and when edits happen to fields that affect calculations, I need to rerun my calculations and update those table columns that represent results of those calculations.

Is there some kind of best practice implementing something like this?
I thought about a custom save function in the admin panel, that does just that - rerun the calculations and update the database entries.

Any hints?

Thanks in advance!

Hello there!
That depends, I would say it’s fine for you to have that as an admin custom save function as long as it’s only one row that needs to be recalculated.
Otherwise having to update all rows could take up some time and may not be ideal to have that on the request/response flow, then you could use something like celery to handle this asynchronously, using your admin custom save function to dispatch the task.