简体   繁体   English

Django网站框架权限

[英]Django sites framework permissions

I am using the sites framework to run multiple apps off of one code base. 我正在使用网站框架从一个代码库运行多个应用程序。 I have 3 users, and 3 sites. 我有3个用户和3个站点。 They can login to the django admin interface and create content but I want them to see only the site they are allowed to manage, not the others, can the sites framework handle this? 他们可以登录django管理界面并创建内容,但是我希望他们仅看到允许其管理的网站,而不能查看其他网站,该网站框架可以处理吗? if not can anyone guide me to the right direction as to how this can be accomplished? 如果不能,那么任何人都可以引导我朝正确的方向前进,以实现这一目标?

EDIT: 编辑:

What I did was a simple example. 我所做的只是一个简单的例子。 Here goes.... 开始....

class Weblog(models.Model):
    title = models.CharField(max_length=250)
    slug = models.SlugField(unique=True)
    user = models.ForeignKey(User) # this is the user who should own that blog and see nothing else
    site = models.ForeignKey(Site)

    objects = models.Manager()
    on_site = CurrentSiteManager()

    def __unicode__(self):
        return self.title

class Entry(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField()
    body = models.TextField()
    author = models.ForeignKey(User)
    weblog = models.ForeignKey(Weblog)

This is where I am confused. 这就是我感到困惑的地方。 I understand the concept of a weblog having a reference to a site and a user as well. 我了解网志的概念,其中也包含对网站和用户的引用。 But then how does one limit that person to only see and add/edit the entries on their own weblog that was created for them? 但是,如何限制该人只在自己为他们创建的Weblog上查看和添加/编辑条目?

Thanks 谢谢

Yes, the Django sites framework can do exactly that. 是的,Django站点框架可以做到这一点。 As I have not much information about what you already did, I can't really help you, so please give more details. 由于我没有太多关于您已经做过的信息,因此我无法真正为您提供帮助,请提供更多详细信息。

Also check the specific documentation . 还要检查特定的文档

EDIT Ok, I understand it now, your problem is to restrict users to only view and edit content about their dedicated site. 编辑好的,现在我知道了,您的问题是限制用户仅查看和编辑有关其专用站点的内容。 This is a little more complicated. 这有点复杂。

It depends if you use the admin interface or custom views to handle this views and edits. 这取决于您使用管理界面还是自定义视图来处理此视图和编辑。 If you use custom ones it can be done easily changing the queryset used, but I imagine you use the admin interface. 如果使用自定义变量,可以很容易地更改所使用的查询集,但是我想您会使用管理界面。

In this case, maybe overriding the default manager (objects) with CurrentSiteManager() can do the job. 在这种情况下,也许可以使用CurrentSiteManager()覆盖默认的管理器(对象)即可。 But

  • it can have side effects, overriding the default manager is not recommended, you need to test it (the first side effect is: you won't have a listing of all edits on all sites) 它可能会有副作用,不建议您覆盖默认管理器,您需要对其进行测试(第一个副作用是:您不会在所有网站上都列出所有修改内容)
  • you must be sure that user A can't login in site B admin interface 您必须确保用户A无法登录站点B的管理界面

Another solution may be to create custom admins for each one of these websites. 另一个解决方案可能是为这些网站中的每个网站创建自定义管理员。 See the admin doc. 请参阅管理文档。

But, just a question: if you don't want to let users edit content on each of these websites, do you however need to have a unique interface to all this admin websites? 但是,这只是一个问题:如果您不想让用户编辑这些网站中的每个网站上的内容,那么您是否需要对所有这些管理网站都具有唯一的界面? For example to let one person be able to edit content on all the sites) If not, maybe the Sites framework is not the way to go, and you should better make each website independant and clearly separated? 例如,让一个人可以编辑所有网站上的内容)如果没有,也许网站框架不是走的路,而您最好使每个网站独立且清晰地分开吗?

Another solution is to look to the permissions possibilities of Django which let you define custom permissions to your views. 另一个解决方案是利用Django的权限可能性,该权限使您可以定义视图的自定义权限。 I think (haven't tried it) it can also be used to protect admin views. 我认为(尚未尝试过)它也可以用于保护管理员视图。

I hope this can help. 希望对您有所帮助。

Django-site-permissions application would do exactly that: Django-site-permissions应用程序将执行以下操作:

https://github.com/bmihelac/django-site-permissions https://github.com/bmihelac/django-site-permissions

You can integrate it in your project if it meets your needs or check the source code to see how site wide permissions can be implemented. 您可以根据需要将其集成到项目中,也可以查看源代码以了解如何实现站点范围的权限。

(disclaimer: I am the developer of django-site-permissions app) (免责声明:我是django-site-permissions应用程序的开发人员)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM