2

i've changed the app label doing this

class Model(models.Model):
     pass

     class Meta:
          app_label = 'App Name'
          db_table = 'app_table'

The table and application already existed, the problem is that when i go to the admin interface, only the superusers can view the app, and other users not, i tried to add permissions to the other user but it does not appear in the permissions box.

Thanks in advance!

4

4 回答 4

2

This is definitely a bug in Django. There's a conflict between the permission app_label and the contenttype app_label, result in the permission never matching in the admin. As a workaround until this is fixed, you can simply explicitly grant permission on the ModelAdmin:

class MyModelAdmin(admin.ModelAdmin):
    ...
    def has_add_permission(self, request):
        return request.user.has_perm('app_label.add_modelclass')

    def has_change_permission(self, request, obj=None):
        return request.user.has_perm('app_label.change_modelclass')

    def has_delete_permission(self, request, obj=None):
        return request.user.has_perm('app_label.delete_modelclass')

Where app_label is the app_label of the root model and modelclass is the lowercase name of your proxy model.

于 2011-05-24T16:48:46.070 回答
0

app_label影响数据库表名和内容类型条目。就好像您的模型将被移动到其他应用程序一样。权限取决于内容。Syncdb 将修复内容类型,将创建新表,将创建新的权限条目。您需要为该模型上的现有用户/组添加权限,该模型已“移动”到其他应用程序。

于 2011-02-11T17:28:42.437 回答
0

这可能对您有用:

像往常一样定义您的模型类,即:

class MyModel(models.Model):
     pass

     class Meta:
          db_table = 'app_table'

然后创建一个代理模型,并更改该代理模型的 App 标签,第二个模型如下所示:

class MyProxyModel(MyModel):
     pass

     class Meta:
          proxy = True
          app_label = 'app_name'

注意:您的 App 标签应该全部小写并且包含下划线而不是空格,Django 会自动替换下划线并将应用标签大写。

然后注册您创建的任何 ModelAdmin 代理模型。

admin.site.register(MyProxyModel,MyModelAdmin)

这应该让您的 MyModelAdmin 显示在管理界面中不同的 App 标签下。我不肯定这会解决权限问题,因为我现在没有测试它的环境,但它会显示在另一个标签下。

于 2011-02-12T01:57:11.587 回答
0

我不确定您是否按照此处的预期使用 app_label。如果您想提高模型名称的可读性,请在模型的元类中使用verbose_name 。

app_label似乎没有最好的文档,但据我所知,它应该是一个机器可读的名称。

于 2011-02-11T16:54:17.230 回答