在生产中使用 Django Flatpages:如何归档更改以进行恢复

发布于 2024-09-13 01:32:34 字数 546 浏览 2 评论 0原文

我在生产站点中使用 Django Flatpages。我想找出最好的方法来确保如果管理员在编辑文件时出错,可以检索旧版本的页面。我们有备份等,但是恢复起来有点麻烦(即涉及系统管理员,而不是网站编辑器)。

首先,有没有一个包可以做到这一点?我不需要将所有数据库更改存档到文件系统或 MongelDB 的东西,但可能需要 Flatpages 附加组件。

如果没有,我想出了两种替代方案:

  1. 只需拥有一个临时服务器,所有实时更改都会在其中发生,然后加载到生产环境中

    Django 平面页面备份?

  2. 一些监视数据库的外部脚本,并在看到 Flatpages 内容的更改后,将最新内容的副本保存在其他表中,例如 FlatpagesHistory。然后网站编辑器可以使用管理服务从 FlatpagesHistory 检索页面的旧副本。有人做过吗?

感谢您的反馈。

谢谢。

I am using Django Flatpages in a production site. I'd like to figure out the best way to make sure if an admin makes a mistake editing a file, old version of the page can be retrieved. We have backups and such, but that's a bit more cumbersome to recover from (i.e. involves sysadmin, not website editor).

First, is there a package that does this? I don't need something that archives all db changes to the filesystem or MongelDB, but perhaps a Flatpages add-on.

If not, I came up with two alternatives:

  1. Just have a staging server where all the live changes happen, then load on production

    Django flatpages backup?

  2. Some external script that monitors DB, and upon seeing changes to Flatpages contents, save a copy of the latest content in some other table, like FlatpagesHistory. Then website editor can just use Admin service to retrieve old copies of the pages from FlatpagesHistory. Has anyone done this?

I appreciate your feedback.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜清冷一曲。 2024-09-20 01:32:34

没有得到回应,所以我正在挖掘一些。事实证明您可以非常轻松地实现这一点。

创建一个像这样的模型:

class OldPage(models.Model):
    """
    Keep old contents from flatpages.
    """
    url = models.CharField('URL',max_length=100, db_index=True)
    title = models.CharField(max_length=200)
    content = models.TextField(blank=True)
    mtime = models.DateTimeField('Modified', db_index=True, auto_now_add=True)
    user = models.ForeignKey(django.contrib.auth.models.User)

然后在 admin.py 文件中,像这样覆盖 Flatpage admin

class MyFlatPageAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        """save a copy of the Flatpage to OldPage"""
        history = OldPage()
        history.url = obj.url
        history.title = obj.title
        history.content = obj.content
        history.user = request.user
        history.save()
        obj.save()

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, MyFlatPageAdmin)

你可以为你的 OldPage 有一个“只读”管理界面,就像这样

class OldPageAdmin(admin.ModelAdmin):
    readonly_fields = ('url','title','content','mtime','user')
    list_display = ('url','mtime','user','title')
    date_hierarchy = 'mtime'

admin.site.register(lims.pages.models.OldPage, OldPageAdmin)

Didn't get a response, so I was digging a bit. Turns out you can just implement this very easily.

Create a model like this:

class OldPage(models.Model):
    """
    Keep old contents from flatpages.
    """
    url = models.CharField('URL',max_length=100, db_index=True)
    title = models.CharField(max_length=200)
    content = models.TextField(blank=True)
    mtime = models.DateTimeField('Modified', db_index=True, auto_now_add=True)
    user = models.ForeignKey(django.contrib.auth.models.User)

Then in a admin.py file, override flatpage admin like this

class MyFlatPageAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        """save a copy of the Flatpage to OldPage"""
        history = OldPage()
        history.url = obj.url
        history.title = obj.title
        history.content = obj.content
        history.user = request.user
        history.save()
        obj.save()

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, MyFlatPageAdmin)

And you can have a "read-only" admin interface for your OldPage, like this

class OldPageAdmin(admin.ModelAdmin):
    readonly_fields = ('url','title','content','mtime','user')
    list_display = ('url','mtime','user','title')
    date_hierarchy = 'mtime'

admin.site.register(lims.pages.models.OldPage, OldPageAdmin)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文