database - How to have a version control in django? -
i have django webapp different content (e.g. posts, threads, comments) , want keep track of history. i'm trying create "version-control" "content". how i'm doing (skip end question):
i have model create_content
represents action: has actor (editor
), set of modifications (edition
), timestamp, , content acts on:
class create_content(models.model): editor = models.foreignkey('user') edition = models.textfield() # pickled dictionary date = models.datetimefield(auto_now_add=true) content = models.foreignkey('content')
which saved once because history cannot changed.
i define content has:
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
last action performed it, , first_edition
use initial author of content.
all actual content of webapp implemented derived models of content, created/edited derived models of create_content
. instance,
class comment(content): post = models.foreignkey(post, related_name="comment_set") body = models.textfield()
is created during save of create_comment(create_content)
(in fact subclasses of create_content
proxies).
for instance, user editions instances of subclass of create_content
(e.g. edit_comment(create_content)
) which, during save()
, makes last_edit
point onto self
, updates actual content (e.g. edit_comment.body
).
in end i'm doing simplified version of git database:
create_content
commits (which store complete state inself.edition
).content
specific branch+working directory (last_edit
being pointer),- a user edition moves branch forward , changes
content
's new content (e.g.body
ofcomment
).
brief ending
what realized every user action have entry in table of create_content
.
my question are:
how bad happen? mean, table can pretty big, , actions hitting it.
i think approach "clean", i'm pretty sure i'm re-inventing wheel. specific wheel?
you can try: https://bitbucket.org/emacsway/django-versioning. django-versioning allows version data stored in django models, , stores diff, not content copy. supports field types excepts manytomany (currently).
maybe useful project: django built-in comments app , way of referring objects. think nice , clean approach.
the physical database size doesn't matter. number of records doesn't matter. see: how big can mysql database before performance starts degrade
but how useful keep full history? start delete history timemachine does. have daily (for week), weekly (for months) , monthly records. crontab or django-celery delete old history.
Comments
Post a Comment