Django多用户saas [英] Django multi-user saas

查看:218
本文介绍了Django多用户saas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为学习目的创建一个小的saas ...我知道最好的方式是为每个用户分别设置一个模式...但是我的saas是一个小应用程序,我真的不需要单独的模式加上它会使事情变得复杂(后来对模式的更改)...所以我将为所有用户使用相同的模式,只需将每个用户的ID添加到该条目中,然后在登录时只显示用户的条目。 / p>

有没有办法通过中间件登录时可以预先填写用户的ID?还是需要调整所有查询(按用户ID进行过滤)?我已经将用户的ID存储在他的条目中...所以我只需要这个选项。



谢谢!

解决方案

我不知道有什么办法可以根据request.user自动过滤查询。这是因为ORM与django.contrib.auth不兼容。



我尝试过两种SaaS设计:


  1. 所有站点的数据库,并手动过滤所有查询。当然这使得django.contrib.admin不可能开箱即用。可能通过 django-authority 的真正紧凑的设置来启用django.contrib.admin或者甚至其他django每个对象的权限包 google缓存版本,因为djangopackages.com是ATM ATM) / p>


  2. 每个站点1个数据库,这更简单,保持代码清洁,并启用django.contrib.admin开箱即用,如果您安装 django管理主题,这可能非常酷。此外,我启用了 django.contrib.admindoc 以及< a href =https://github.com/jezdez/django-dbtemplates =nofollow> django-dbtemplates 。


(显然在你的情况下,1个站点= 1个用户,但概念是一样的)



我更喜欢第二个实现,因为它是显然很少的开发工作,这得到一点系统管理的补偿。


I'm creating a small saas for learning purposes... I know that the best way to go is to have a separate schema for each user... But my saas is a small app and I really don't need separate schemas plus it would complicate stuff (later alterations to the schema)... So I'm going to use the same schema for all users and just append each user's ID to the entry and then display only the user's entries upon login.

Is there a way I can "prepend" user's ID upon login through middleware? Or do I need to adjust all the queries (filter by user's ID)? I already store the user's ID to his entries... so I need this only for select's.

Thank you!

解决方案

I don't know of any way to automatically filter querysets based on request.user. This is because the ORM is not coupled with django.contrib.auth.

I tried two SaaS designs:

  1. 1 database for all sites, and manual filtering on all querysets. Of course this made django.contrib.admin not possible out of the box. It might be possible to enable django.contrib.admin with a really tight setup of django-authority or maybe even other django per-object permission packages (google cached version because djangopackages.com is down ATM).

  2. 1 database per site, that's just easier, keeps the code cleaner, and enables django.contrib.admin out of the box, which can be really cool if you install a django admin theme. Also I enabled django.contrib.admindoc as well as django-dbtemplates.

(Apparently in your case, 1 site = 1 user, but the concept is the same)

I prefer the second implementation because it's obviously a lot less development work, which is compensated by a little system administration.

这篇关于Django多用户saas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆