So I want to track some fields in model,therefore I used pghistory
this is my code:
@pghistory.track(
pghistory.BeforeUpdate(
"trailer_changed",
condition=pgtrigger.Q(
old__rate__df=pgtrigger.F("new__rate"),
old__truck__df=pgtrigger.F("new__truck"),
),
),
fields=["rate", "truck"],
model_name="trailertracker",
)
but problem is that, if I change only “rate” field, it also saves unchanged value of “truck” field too, then when I want to display changes on front, I get messed up, because there is also unchanged values too, example: if I change only truck field 10 times, in DB result will be like this
rate - truck
value1 - changed_value1
value1 - changed_value2
value1 - changed_value3
value1 - changed_value4
value1 - changed_value5
value1 - changed_value6
value1 - changed_value7
value1 - changed_value8
......
how can I resolve this? that would be good if I save for unchanged field “None” or null or something else
Btw, what is the best practice to save history tracker? for other models I have to track about 10 fields, and is it ok to use like that? or should I create tracker table for every field?