本文介绍了Django代理模型权限不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序扩展了Django管理员网站,以允许非员工/超级用户访问。这是正常工作。



我为现有模型创建了一个代理模型,并将其注册到我的管理网站,但是对于非员工用户来说,它不会出现。从我阅读的文档中,我的理解是代理模型获得自己的权限。我检查过,这些不会出现在可用权限列表中。



这是我的代码,以防它有帮助:



正常模型



 类Engagement(models.Model):
eng_type = models.CharField(max_length = 5)
environment = models.CharField(max_length = 8)
is_scoped = models.BooleanField()

class Meta:
ordering = ['eng_type','environment']
app_label ='myapp'

代理模型

  class NewRequests(Engagement):
class Meta:
proxy = True
app_label ='myapp'
verbose_name ='新请求'
verbose_name_plural ='新请求'

模型管理

  class NewRequestsAdmin(ModelAdmin):
pass

def queryset(self,request):
return self.model.objects.filter(is_scoped = 0)

自定义管理员注册

  myapps_admin_site.register(NewRequests,NewRequestsAdmin)

我一直在管理我的数据库。根据,您必须按照指示用户指向。这是一个失败。我的数据库没有很多信息,所以我取消了南方的注释,并运行了一个常规syncdb来排除南方。不幸的是,这还不行,我很失落。任何帮助都不胜感激。



修改



这是在Django 1.4


解决方案

原来我没有做错什么。我正在寻找



myapp |新请求|可以添加新的请求



权限属于父模型。



myapp |参与|可以添加新的请求


I extended Django admin site for my app to allow non-staff/superusers access. This is working just fine.

I created a proxy model for an existing model and registered it to my admin site, however, it doesn't appear for non-staff users. From the documentation I read, my understanding is that proxy models get their own permissions. I checked and these don't appear in the list of available permissions.

Here's my code in case it helps:

Normal Model

class Engagement(models.Model):
    eng_type = models.CharField(max_length=5)
    environment = models.CharField(max_length=8)
    is_scoped = models.BooleanField()

    class Meta:
        ordering = ['eng_type', 'environment']
        app_label = 'myapp'

Proxy Model

class NewRequests(Engagement):
    class Meta:
        proxy = True
        app_label = 'myapp'
        verbose_name = 'New Request'
        verbose_name_plural = 'New Requests'

Model Admin

class NewRequestsAdmin(ModelAdmin):
pass

def queryset(self, request):
    return self.model.objects.filter(is_scoped=0)

Custom Admin Registration

myapps_admin_site.register(NewRequests, NewRequestsAdmin)

I've been managing my DB with South. According to this post, you have to tamper with it a bit by following the instructions it points users to. This was a failure. My DB doesn't have a whole lot of info in it, so I uncommented South and ran a regular syncdb to rule out South. Unfortunately, this is still not working and I'm at a loss. Any help is appreciated.

Edit

This was on Django 1.4

解决方案

Turns out I didn't do anything wrong. I was looking for the permissions under

myapp | New Request | Can add new request

Permissions fall under the parent model.

myapp | engagement | Can add new request

这篇关于Django代理模型权限不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 14:35