多个 Django 管理实例

发布于 2024-12-11 00:49:35 字数 581 浏览 0 评论 0原文

我需要构建一个可供多家公司使用的 django admin 实例。 架构是:

Company1
     Branch 1
          User 1
          User 2
     Branch 2
          User 3
          .......

Company 2
     Branch 1
          User 4
          User 5
     Branch 2
          User 6
          .......

这背后的想法是用户 1 和 2 能够看到(但不能编辑)用户 3 的内容。用户 1 和 2 可以查看和编辑彼此的内容。所有这些都在 Company1 范围内(仅)。

我的问题是,是否有开发人员遇到过类似的问题,并想分享他们对如何在 dj admin 中实现这一目标的想法?是否有任何其他软件包可用于朝正确方向扩展 dj 管理功能?

我知道这对 dj admin 的设计目的提出了挑战(无需对此谨慎)...但是由于没有足够的人手来为这个项目从头开始设计和构建一些东西,我需要利用 dj尽可能多地管理功能。

所有的想法将不胜感激!

I need to build one instance of django admin that can be used by multiple companies.
the schema is :

Company1
     Branch 1
          User 1
          User 2
     Branch 2
          User 3
          .......

Company 2
     Branch 1
          User 4
          User 5
     Branch 2
          User 6
          .......

The idea behind this is that user 1 and 2 is able to see (but cannot edit ) user's 3 stuff. Where as users 1 and 2 can see and edit each other's content. All this within the Company1 scope (only).

My question is are there any devs out there who's faced a similar problem and want to share their thoughts on how this can be achieved in dj admin? Any additional packages which can be utilized to extend dj admin functionality in right direction ?

Im aware that this challenges the idea of what was dj admin designed for (no need to caution about this ) ... but since there isn't enough hands to design and build something from a scratch for this project i need to tap into dj admin functionality as much as i can.

All thoughts will greatly be appreciated !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她如夕阳 2024-12-18 00:49:35

我也遇到过类似的情况,附加的要求是用户可以在多个公司工作,并且可以“切换”。为此,我将“当前公司”放入一个会话中。如果在您的情况下,您只是在用户中查找他们被允许看到的内容,那么通过覆盖 ModelAdmin.queryset 应该非常容易,例如:

class CompanyGogglesAdmin(admin.ModelAdmin):
    def queryset(self, request):
        qs = super(CompanyGoggleAdmin, self).queryset(request)
        user_company = request.user.company
        return qs.filter(**{ 'company' : user_company })

您可以使用 CompanyGogglesAdmin 作为所有这些模型的基类可以通过用户公司查找的“公司”进行过滤。您还可以使该公司字段可配置,或者像我一样从会话而不是用户中查找“当前”公司。另请参阅 如何实现全局隐式在 Django 管理中过滤?

I was in a similar situation, with the added requirement that a user may be in multiple companies, and can "switch". For that purpose I put the "current company" into a session. If in your case you'd just be looking up in the user what they're allowed to see, it should be very easy, by overriding ModelAdmin.queryset, for example:

class CompanyGogglesAdmin(admin.ModelAdmin):
    def queryset(self, request):
        qs = super(CompanyGoggleAdmin, self).queryset(request)
        user_company = request.user.company
        return qs.filter(**{ 'company' : user_company })

You could use CompanyGogglesAdmin as a base class for all those models that can be filtered by "company" which gets looked up by the user's company. You could also make that company field configurable, or - like I did - look up the "current" company from a session rather than the user. See also How can I implement a global, implicit filter in Django admin?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文