Python / Django多租户解决方案 [英] Python / Django multi-tenancy solution
问题描述
我可以使用一些帮助为我正在开展的项目创建一个攻击计划。
I could use some help creating a plan of attack for a project I'm working on.
想象一下,该网站是一个负责区域销售办事处的小组,分布在世界各地。这个项目的目的是为了让超级员工以更快的速度,为每个办公室提供一个新的子站点 - 频繁添加站点。办公室子站点应完全包含该子站点的管理用户,并且应该是用户友好的CMS。超级用户应该能够进入并管理所有这些办公室子站点。
Imagine that the site is for a group that oversees regional sales offices, distributed around the world. The purpose of this project is to let superusers spin up a new sub-site specific to each and every office, at a fast pace -- sites are added on a frequent basis. The office sub-sites should be wholly contained with "admin" users specific to that sub-site and should be user-friendly CMS. A superuser should be able to step in and manage all of these office sub-sites.
除了独立的办公室子站点实例,还有一个需要每个子站点管理联系人,线索等,并将其存储在超级用户的一个中心区域。
In addition to the self-contained office sub-site instance, there is also a need for each sub-site to manage contacts, leads, etc and store this in one central area for the superusers.
我已经使用Django做了几个网站,但是没有任何多租户。我想要使用技术的建议或可能有帮助的教程/文档。
I've done a few sites using Django, but never anything multi-tenant. I'd like suggestions for technologies to use or tutorials/documentation that might be helpful.
要求:
- 每个子站点使用相同的源(模板,JS,可用功能等),但可以修改以反映模板中的自定义内容。
- 已分配
- 子站点(具有使用完全限定域的选项),在项目中配置,而不是硬编码的设置文件。 子站点特定用户访问控制可以访问所有子站点的超级用户。
- 为每个子站点提供独立CMS的能力。即,一个子站点管理员只看到他们的内容。我对这个项目的偏好是django-cms,但我可以接受建议。
- 支持从所有子站点汇集数据但限制子站点的应用程序管理员只能查看他们的记录到那个应用程序。
- Each sub-site uses the same source (templates, JS, available features, etc), but can be modified to reflect custom content within the templates.
- Assigned subdomains (with an option of using a fully qualified domain) per sub-site, configured within the project, not in a hardcoded settings file.
- Sub-site specific user access controls, in addition to superusers who can access all sub-sites.
- The ability to provide an "independent" CMS for each sub-site. i.e., A sub-site admin only sees their content. My preference for this project would be django-cms, but I'm open to suggestions.
- Support for apps that pool the data from all the sub-sites, but limit sub-site "admins" to only viewing their records into that app.
考虑到上述,你会推荐什么方法?我很乐意重新考虑技术,但我想坚持使用Python。
Considering the above, what approach would you recommend? I am open to reconsidering technologies, but I would like to stick with Python.
推荐答案
有一个很好的应用程序称为 django-tenant-schemas ,它使用PostgreSQL模式机制来创建多租户。
There is a great app called django-tenant-schemas that uses PostgreSQL schemas mechanism to create multi-tenancy.
您获得的是包含所有模式(子站点)共享的对象的 SHARED_APPS
和 TENANT_APPS
包含特定于子站点的对象,即用户,记录等。模式彼此完全隔离。
What you get is specyfing SHARED_APPS
that contain objects shared across all the schemas (sub-sites), and TENANT_APPS
that contain objects specific for a sub-site, i.e. users, records etc. The schemas are completely isolated from each other.
每个PostgreSQL模式绑定到一个域url,所以中间件检查请求的 HOST
部分,并将db连接的模式设置为appriopriate一个。
Each PostgreSQL schema is tied to a domain url, so that middleware checks the HOST
part of the request and sets the db connection's schema to appriopriate one.
此外,它允许您定义一个 PUBLIC_SCHEMA_URLCONF
,它允许您为 public 模式指定urlconf文件 - 不绑定到任何子位点。
In addition, it allows you to define a PUBLIC_SCHEMA_URLCONF
which allows you to specify urlconf file for public schema - the meta site that is not tied to any sub-site.
这篇关于Python / Django多租户解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!