How to maintain order of paragraphs in a Django document revision system?
Editors often solve this problem with a Piece Table. The table is a list of objects that point to spans of characters that are a) contiguous in memory, and b) share common attributes. The order of the pieces in the table is used for mapping character-in-document addresses to memory and vice versa. By reordering the piece table you effectively reorder the document without moving anything around. The key point is that the piece table itself is independent of the objects that make up the content of the document.
So one way of mapping your paragraph order would be to have a simplified version of a peice table. This could be as simple as a list of para-ids in document order. When you need to change something, you fetch the list, unpickle it, make you edits on the list, pickle and save.
Another advantage of the table is that it greatly simplifies implementing undo. The history file is a simple list of edits to the table, and undoing/redoing is a matter of reversing or reapplying a particular edit to the table, the data itself doesn't change. This should play well with any versioning you want to do.
I'm having trouble figuring out how to best implement a document (paragraph-) revision system in Django.
I want to save a revision history of a document, paragraph-by-paragraph. In other words, there will be a class Document, which has a ManyToManyField to Paragraph. To maintain the order of the paragraphs, a third class ParagraphContainer can be created.
My question is, what is a good way to implement this in Django so that the order of paragraphs is maintained when someone adds a new paragraph in-between existing paragraphs? 
One obvious way would be to have a position attribute in the ParagraphContainer class, but then this field will have to be updated in all paragraphs following the inserted (or deleted) paragraph. A linked list is another option, but I'm scared that might be very slow for retrieval of the whole document. Any advice?