如何从 Wagtail 数据库中删除旧版本?我发现每次进行更改时,页面的先前版本都会保留在数据库中......非常好,但是我如何“取出垃圾?”
换句话说:“好吧,这个页面现在已经完成了,我不想再保留以前的修订版了。”您可能认为这很容易 - 但是,它在哪里?
修订存储在
wagtail.core.models.PageRevision
模型中,即数据库中的 wagtailcore_pagerevision
表。要删除给定页面的所有修订,您可以从 ./manage.py shell
运行以下命令:
from wagtail.core.models import PageRevision
PageRevision.objects.filter(page_id=123).delete()
请注意,“另存为草稿”和“提交审核”工作流程也可以通过保存 PageRevision 条目来工作,因此您应该仅在页面以您想要保留的状态发布后才执行此操作。
自 Wagtail 2.10 起,存在一个管理命令,该命令应清除修订(清除旧修订,保留最新修订):
$ ./manage.py purge_revisions --help
usage: manage.py purge_revisions [-h] [--days DAYS] [--pages] [--non-pages]
[...]
Delete revisions which are not the latest revision, published or scheduled to
be published, or in moderation
options:
-h, --help show this help message and exit
--days DAYS Only delete revisions older than this number of days
--pages Only delete revisions of page models
--non-pages Only delete revisions of non-page models
[...]