Creating Energy log table for several Django models

Asked

Viewed 96 times

0

I have 30 models. Each of them contains information from a calculator and each record is information from sub-calculators. I need to create a log table of each calculation made by the user.

Currently I am saving the JSON of what the guy sends and saving also the result in JSON. Because each calculator has different fields and different results (some are lists, other variables and other dictionaries).

Is there a better way to do that? The problem I’m facing is that if I want to take reports/metrics out of all the data I would have to create a script to get and transform (from each calculation done per user). Thing that if I had saved everything in a model would be easier (with Django).

The problem is that I would then have to create 30+ models. Or else I would have to create hundreds of fields that all calculators have and also fields with all possible results. It gets a little confusing to imagine that.

Could someone give me a hint before this scenario?

  • 1

    A suggestion would be to use the jsonb type field in postgres, Django has mapping for it. This way you could have a model with some columns that would be standard for everyone and a jsonb field with the specific information of each calculator.

1 answer

2

I recommend using Lib Django Activity Stream.

It is possible to create logs dynamically, with specific information about actor, action and target of the action.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.