Is there a way I can remove all the permission that Django creates by default and prevent it from creating them again?
有没有办法可以删除Django默认创建的所有权限,并阻止它再次创建它们?
Currently I have a migration that runs a Permission.objects.all().delete()
and I also have added default_permissions = ()
to the Meta
class of all my models, and yet once I run the migration, the permissions disappear for a second, and then Django recreates them (I know it's a genuine recreation because the ID of each permission increases each time I run the migration).
目前我有一个运行Permission.objects.all()。delete()的迁移,我还将default_permissions =()添加到我所有模型的Meta类中,但是一旦我运行迁移,权限就会消失第二,然后Django重新创建它们(我知道它是一种真正的娱乐,因为每次运行迁移时每个权限的ID都会增加)。
So, is there a way I can completely disable automatic permission creation? Note that I'm saying disable creation, not hiding permissions (which I already know how to do).
那么,有没有办法可以完全禁用自动权限创建?请注意,我说的是禁用创建,而不是隐藏权限(我已经知道该怎么做)。
1 个解决方案
#1
0
Have you looked into creating an app that has a post_migrate signal to do this?
您是否考虑过创建一个具有post_migrate信号的应用程序来执行此操作?
I understand that all of the auth app's permission creating code happens when it calls its post_migrate function. See here and here
我知道创建代码的所有auth应用程序的权限都在调用其post_migrate函数时发生。看到这里和这里
It should be the case that default_permissions = ()
should prevent creating permissions for the models you specify that in its Meta class, however since you can't do that on third party or django installed apps, you're left with those permissions in your DB till your new clean up post_migrate signal comes along and cleans them up.
应该是这样的情况,default_permissions =()应该阻止为你在Meta类中指定的模型创建权限,但是因为你不能在第三方或django安装的应用程序上执行此操作,所以你留下了这些权限DB直到你的新清理post_migrate信号出现并清理它们。
Hope that helps
希望有所帮助
#1
0
Have you looked into creating an app that has a post_migrate signal to do this?
您是否考虑过创建一个具有post_migrate信号的应用程序来执行此操作?
I understand that all of the auth app's permission creating code happens when it calls its post_migrate function. See here and here
我知道创建代码的所有auth应用程序的权限都在调用其post_migrate函数时发生。看到这里和这里
It should be the case that default_permissions = ()
should prevent creating permissions for the models you specify that in its Meta class, however since you can't do that on third party or django installed apps, you're left with those permissions in your DB till your new clean up post_migrate signal comes along and cleans them up.
应该是这样的情况,default_permissions =()应该阻止为你在Meta类中指定的模型创建权限,但是因为你不能在第三方或django安装的应用程序上执行此操作,所以你留下了这些权限DB直到你的新清理post_migrate信号出现并清理它们。
Hope that helps
希望有所帮助