I want to create many chains of the same type records that keep some data in common.
For example:
report id_r:1-> report id_r:1 yesterday <-> report id_r:1 before yesterday
report id_r:2-> report id_r:2 yesterday -> report id_r:2 before yesterday They are all the same Model. 'my_module.report'
How to declare it??
You can use the UnionMixin to create a new model which will contain the record of both models. With this setup you can then for the records of the UnionModel in your report.
That is an interesting idea…
Will try that.
———
Why doesn’t work the simple approach of just creating a field that points to another id of the same table???
It is difficult to answer because we are missing the context. Instead of asking how to implement what you think is the solution, you should explain what you are trying to solve.
Note: there are many link chains in the same table (in parallel — as seen above).
————————————
Now, I solved that in the other way: I created a separate model with inspection results and link (O2M<->M2O) results with inspection occasions accordingly:
I do not see the point to have a link as long as you can order the records per date.
As far as I understand you just need to display for a car the One2Many of inspection ordered per date.
Not really,
as there are many cars and each has its inspections in an arbitrary moment, in result inspections sorted by date-time will result in a mix of unrelated inspections. I redraw the picture in a better way:
Hmmm…
I need to combine all inspections in one record ‘Vehicle’.
Ah! The problem was that Inspection results are not ordered in the correct way (overlaping), in the result — I will lose the general order of inspections, that was kept in the Inspections model.
Also, I understand that I skipped a very important point, sorry: each Inspection is a contract that consists of two inspections: Check-out and Check-in. (i.e. This/Previous).
while vehicles were the third class that remembers all these inspections related to a vehicle:
I agree with @ced, you only need one2 many record by date and with origin(reference)
Eventually, that is exactly how I did that: I created two One2Many records: This & Previous in the Inspection class. They point to related InspectionReslts, and that is ok for the purpose.