【问题标题】:Django Admin Proxy Model Permission Django 1.11Django Admin Proxy 模型权限 Django 1.11
【发布时间】:2018-03-04 20:02:33
【问题描述】:

我在一个应用中创建了一个模型,并在另一个应用中创建了一个代理模型。 现在我想在 Django admin 中只向一组用户授予此代理模型的查看权限。

#core app
class Dress(models.Model):
    name = models.CharField("Nome", max_length=80)

#enza app
class EnzaDress(Dress):
    class Meta:
        proxy = True

在 Django 用户组记录页面的权限网格中,我没有在 Django admin 中看到任何条目授予此代理模型(EnzaDress)的查看权限。

我的 Django 版本是 1.11.5

【问题讨论】:

标签: python django proxy


【解决方案1】:

您应该手动创建权限。

from django.contrib.auth.models import Permission, ContentType

content_type = ContentType.objects.get(app_label='enza', model='enzadress')

Permission.objects.get_or_create(codename='add_enzadress', name='Can add Enza Dress', content_type=content_type)
Permission.objects.get_or_create(codename='change_enzadress', name='Can change Enza Dress', content_type=content_type)
Permission.objects.get_or_create(codename='delete_enzadress', name='Can delete Enza Dress', content_type=content_type)

希望对您有所帮助!

【讨论】:

  • 为您的答案添加一些描述
猜你喜欢
  • 2014-02-22
  • 1970-01-01
  • 2017-10-11
  • 1970-01-01
  • 2019-09-15
  • 2015-02-21
  • 2014-06-18
  • 1970-01-01
  • 2018-07-17
相关资源
最近更新 更多