如何在 Django 项目中拥有 2 个不同的管理站点? [英] How to have 2 different admin sites in a Django project?

查看:19
本文介绍了如何在 Django 项目中拥有 2 个不同的管理站点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个 Django 项目中拥有 2 个独立的管理站点.

I want to have 2 separate admin sites inside a Django project.

我的意思是分开 - 他们应该有单独的用户身份验证,他们应该管理不同的模型,并有不同的外观和 URL.

By separate I mean - they should have separate users authentication, they should administer different models, and have different looks and URLs.

我想要这样做的原因是客户想要单独的部分来管理页面的 CMS 部分,并单独用作后台"解决方案.

The reason I want to do it is the customer wants separate section to administer the CMS part of the page, and separate to use as a 'back-office' solution.

我想在我的项目树中制作一个副本 od django.contrib.auth 应用程序,以不同的方式命名它并为它们两个使用单独的 admin.site.register() 调用.这样我就可以在每个模型中使用其他模型,不同的外观等.我不知道如何解决用户身份验证问题(我应该有不同的用户才能登录 CMS,然后登录 BackOffice).

I thought about just making a copy od django.contrib.auth appliaction in my project tree, naming it differently and using separate admin.site.register() calls for both of them. This way I can have other models available in each one of them, diffrent looks, etc. I don't know how to solve the user-authentication problem (I should have different user to be able to log into CMS then into the BackOffice).

以前有人碰巧这样做过,可以给我一些提示吗?还是我打算做的只是设计错误?

Anyone happened to do this before and could give me some hint? Or what I plan to do is just wrong by design?

推荐答案

要在不同的 AdminSites 中注册模型,你只需要创建不同的 django.contrib.admin.sites.AdminSite 实例,看这个.

To register models in different AdminSites you just need to create different instances of django.contrib.admin.sites.AdminSite, see this.

您最好使用两个不同的管理站点来管理不同的模型并拥有不同的模板.对于身份验证和权限,您应该能够按原样使用内置 django.contrib.auth 和自定义权限(希望其他人能够在这里提供更多帮助)

You will be good to go with two different admin sites managing different models and having different templates. For authentication and permissions you should be able to use the build-in django.contrib.auth as is with custom permissions (hope someone else will be able to help more here)

这篇关于如何在 Django 项目中拥有 2 个不同的管理站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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