I have a Django webapp with various content (e.g. posts, topics, comments) and I want to track their history. Therefore, I am trying to create "version control" for "content". Here's how I do it (skip to the end of the question):
I have a Create_Content model that represents an action: it has an actor ( editor ), a set of modifications ( edition ), a timestamp, and the content it affects:
class Create_Content(models.Model): editor = models.ForeignKey('User') edition = models.TextField()
which is saved exactly once, because it is impossible to change the story.
I define the content:
class Content(models.Model): last_edit = models.ForeignKey(Create_Content, related_name='content_last_id') first_edit = models.ForeignKey(Create_Content, related_name='content_first_id') def author(self): return self.first_edit.editor
where last_edit is the last action performed, and first_edition I use to get the original author of the content.
All actual webapp content is implemented by derived Content models that are created / edited by Create_Content derived models. For instance,
class Comment(Content): post = models.ForeignKey(Post, related_name="comment_set") body = models.TextField()
It is created at the time of saving Create_Comment(Create_Content) (in fact, all subclasses of Create_Content are proxies).
For example, custom releases are instances of the Create_Content subclass (e.g. Edit_Comment(Create_Content) ), which, during save() does last_edit to indicate self and updates the actual contents (e.g. Edit_Comment.body ).
At the end, I am making a simplified version of Git for the database:
Create_Content are commits (which save the full state in self.edition ).Content is a specific branch + working directory ( last_edit is a pointer),- The custom version moves the branch forward and changes the
Content to new content (for example, body Comment ).
Brief completion
I realized that every user action will have an entry in the Create_Content table.
My question is:
how bad will this happen? I mean, this table can be quite large, and all actions will hit it.
I think my approach is โclean,โ but I'm sure I am reinventing the wheel again. What is this particular wheel?