如何在Django中进行版本控制? [英] How to have a version control in django?

查看:117
本文介绍了如何在Django中进行版本控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Django webapp,其中包含不同的内容(例如,帖子,主题,评论),我想跟踪它们的历史.所以我试图为内容"创建一个版本控制".这就是我的做法(跳到问题的最后):

I have Django webapp with different content (e.g. Posts, Threads, comments) and I want to keep track of their history. So I'm trying to create a "version-control" for "content". This is how I'm doing it (skip to the end for the question):

我有一个表示动作的模型 Create_Content :有一个演员( editor ),一组修改( edition ),一个时间戳及其作用的内容:

I have a model Create_Content which represents an action: has an actor (editor), a set of modifications (edition), a timestamp, and the content it 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 is saved exactly once because history cannot be changed.

我定义的内容具有:

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

其中 last_edit 是执行它的最后一个动作,而 first_edition 是我用来获取内容的最初作者的

where last_edit is the last action performed it, and first_edition I use to get the initial author of the content.

webapp的所有实际内容均由Content的派生模型实现,这些派生模型由 Create_Content 的派生模型创建/编辑.例如,

All the actual content of the webapp is implemented by derived models of Content, which are created/edited by derived models of Create_Content. For instance,

class Comment(Content):
    post = models.ForeignKey(Post, related_name="comment_set")
    body = models.TextField()

是在保存 Create_Comment(Create_Content)时创建的(实际上 Create_Content 的所有子类都是代理).

is created during the save of Create_Comment(Create_Content) (in fact all subclasses of Create_Content are proxies).

例如,用户版本是 Create_Content (例如 Edit_Comment(Create_Content))的子类的实例,在 save()期间,使 last_edit 指向 self 并更新实际内容(例如 Edit_Comment.body ).

For instance, user editions are instances of a subclass of Create_Content (e.g. Edit_Comment(Create_Content)) which, during save(), makes last_edit to point onto self and updates the actual content (e.g. Edit_Comment.body).

最后,我为数据库做了一个简化版的Git:

In the end I'm doing a simplified version of Git for a database:

  • Create_Content 是提交(将完整状态存储在 self.edition 中).
  • Content 是一个特定的分支+工作目录( last_edit 是指针),
  • 用户版将分支向前移动,并将 Content 的内容更改为新的内容(例如 Comment body )./li>
  • Create_Content are commits (which store the complete state in self.edition).
  • Content is a specific branch+working directory (last_edit being the pointer),
  • A user edition moves the branch forward and changes the Content's to the new content (e.g. body of the Comment).

我意识到,每个用户操作都会在 Create_Content 的表中有一个条目.

What I realized is that every user action will have an entry in the table of Create_Content.

我的问题是:

这有多严重?我的意思是,这张桌子可能很大,所有动作都会击中它.

how bad is this to happen? I mean, this table can be pretty big, and all actions will be hitting it.

我认为我的方法是干净的",但是我很确定自己正在重新发明轮子.这个特定的轮子是什么?

I think my approach is "clean", but I'm pretty sure I'm re-inventing the wheel. What is this specific wheel?

推荐答案

您可以尝试: https://bitbucket.org/emacsway/django-versioning .Django版本允许您对存储在django模型中的数据进行版本控制,并且仅存储diff,而不存储内容副本.支持除ManyToMany(当前)以外的所有字段类型.

You can try: https://bitbucket.org/emacsway/django-versioning. Django-versioning allows you to version the data stored in django models, and stores only diff, not content copy. Supports all field types excepts ManyToMany (currently).

也许对您的项目也很有用:Django内置注释应用程序和引用对象的方式.我认为这是一种不错且干净的方法.

Maybe also useful for your project: the Django built-in comments app and the way of referring to objects. I think this is a nice and clean approach.

物理数据库的大小无关紧要.记录的数量无关紧要.请参阅: MySQL数据库可以有多大在性能开始下降之前获得

The physical database size doesn't matter. The number of records doesn't matter. See: How big can a MySQL database get before performance starts to degrade

但是保留完整的历史记录有多大用处?您可以像TimeMachine一样开始删除历史记录.有每日(一周),每周(几个月)和每月记录.Crontab或Django-Celery可帮助您删除旧历史记录.

But how useful is it to keep a full history? You could start to delete history like TimeMachine does. Have daily (for a week), weekly (for some months) and monthly records. Crontab or Django-Celery help you to delete old history.

这篇关于如何在Django中进行版本控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆