1👍
✅
As discussed, a separate model is a feasible way to go to record all the fragments. We use one IntegerField
to record the fragment order, so that later one the whole Post
could be recovered.
Some caveats here:
- Use
order_by
,latest
or slice n dice operations to sort/find elements. - When insert/delete operations are needed, it’s going to break the overall sequence. We need to increase/decrease multiple elements to maintain the order. Use queryset and
F()
expression to change multiple records at once, like described in another SO post here.
There are some imperfections about the approach, but It’s the best solution I could come up so far(I encountered similar situation before). Linked list is a good way but it’s not database-friendly, as to get all fragments we need O(n) operations instead of O(1) with queryset.
Source:stackexchange.com