在remove_stale_contenttypes之后丢失一些wigtail组权限 - 如何让它们恢复?

问题描述 投票:0回答:1

在我的Django / Wagtail项目中重构一些模型后,我有一些陈旧的内容类型,在wagtail搜索应用程序中触发错误。

可以通过运行contenttypes管理命令来修复这些错误:

./manage.py remove_stale_contenttypes

好的,我收到了关于将要删除的内容的警告,确实列出了一些组权限对象。无论如何,remove_stale_contenttypes做了它的工作,并且wagtail搜索回来了。

但现在缺少一些权限:例如“可以访问wagtail admin”组权限完全丢失,即使对于新的Group实例也是如此。

如何获取默认权限(有些通过wagtail/admin/migration迁移一次)?理想情况下,我想恢复生产网站上的所有“默认”权限...

django wagtail
1个回答
1
投票

以下代码(将在./manage.py shell命令行上运行)应该:

from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission
wagtailadmin_content_type, created = ContentType.objects.get_or_create(app_label='wagtailadmin', model='admin')
admin_permission, created = Permission.objects.get_or_create(content_type=wagtailadmin_content_type, codename='access_admin', name='Can access Wagtail admin')

这是a bug specifically affecting the "Can access wagtail admin" permission type,不应该影响其他权限。

© www.soinside.com 2019 - 2024. All rights reserved.