I am trying to maintain the order of a model with oneToMany relationship. How can I achieve a functionality like storing ArrayField of the model?

Ordering with timestamp won't work as I would like to reorder. Maintaining another table with foreign key for each model and give another field like 1, 2, 3 will work but it might be too expensive if I am thinking on reordering case.

Opinions?

1 Answers

0
Endre Both On

You don't need a separate table, you can simply add an index field to the model on the many side (the one that contains the foreign key).

To reorder, you'd just have to loop over the items in the desired order and rewrite the index field.