Django,如何生成没有模型的管理面板?
我正在构建一个相当大的项目,基本上由以下部分组成:
服务器 1: 冰基服务。 Glacier2 用于会话处理。 允许访问 Glacier2 的防火墙。
服务器2: 通过 Glacier2 提供 Ice 服务的 Web 界面(读取、公共)。 通过 Glacier 2 提供 Ice 服务的管理界面。
我关心的是 Web 界面。我想使用 Django,因为它是用 python 编写的,并且具有非常有用的自动管理面板生成器。
Web 界面不访问任何数据库。它通过 Glacier2 路由器连接到服务器 #1 上的 Ice 服务,并使用这些服务公开的 API 来操作数据。
你可能知道,Django 中的 admin 生成依赖于 Django ORM 的使用;我没有使用它,因为我没有可以访问的数据库。
因此,我需要生成管理面板,但是,我需要拦截任何“db-access”调用并将它们转换为 Ice 服务调用,然后获取服务的输出,而不是像 ORM 通常那样进行标准数据访问(如果有的话),将其转换为 ORM 通常返回的内容并将控制权返回给 Django。
有人知道我该怎么做吗?我需要子类化什么?有什么具体想法吗?
感谢您抽出时间。
I'm building a rather large project, that basically consists of this:
Server 1:
Ice based services.
Glacier2 for session handling.
Firewall allowing access to Glacier2.
Server 2:
Web interface (read, public) for Ice services via Glacier2.
Admin interface for Ice services via Glacier 2.
The point I'm concerned with is the web interface. I want to use Django, because it's both written in python and has that incredibly useful automatic admin panel generator.
The web interface doesn't access any database. It connects to an Ice service on Server #1 via the Glacier2 router and uses the API exposed by those services to manipulate data.
And as you probably know, the admin generation in Django depends on the use of Django's ORM; which I'm not using since I have no database to access.
So I need to generate the admin panel, but, instead of having an standard data access like the ORM normally does, I need to intercept any "db-access" calls and transform them into Ice service calls, and then take the service's output (if any), transform it into whatever the ORM normally returns and return control to Django.
Anyone knows how I could do this? what would I need to subclass? Any specific ideas?
Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为可能有比编写自定义 ORMS 更简单的方法来获得您想要的管理集成。我在一个应用程序中使用了它,该应用程序允许通过控制面板 API 管理 Webfaction 电子邮件帐户。
在这里查看 models.py、admin.py 和 urls.py:django-webfaction
要在管理索引页面上创建条目,请使用已 Managed=False 的虚拟模型
向管理员注册该模型。
然后,您可以拦截管理 URL 并将它们定向到您自己的视图。
如果管理员提供的添加/编辑/删除操作对您的应用程序有意义,那么这是有意义的。否则,您最好覆盖管理索引或更改列表模板以包含您自己的自定义操作
I think there might be a simpler way than writing custom ORMS to get the admin integration you want. I used it in an app that allows managing Webfaction email accounts via their Control Panel API.
Take a look at models.py, admin.py and urls.py here: django-webfaction
To create an entry on the admin index page use a dummy model that has managed=False
Register that model with the admin.
You can then intercept the admin urls and direct them to your own views.
This makes sense if the add/edit/delete actions the admin provides make sense for your app. Otherwise you are better off overriding the admin index or changelist templates to include your own custom actions
contrib.admin 的真正威力是 django Forms。本质上,管理工具基本上是自动生成一个表单来匹配模型,并添加一些 urls.py 路由。最终,除了管理工具之外,使用 django Forms 可能会更容易。
The real power of the contrib.admin is django Forms. In essence, the admin tool is basically auto-generating a Form to match a Model with a little bit of urls.py routing thrown in. In the end it would probably just be easier to use django Forms apart from the admin tool.
您可以“模拟”某个类,使其看起来像一个模型,但它确实代理您的 API,
例如
这可能有效..但是你需要做很多 django.model 兼容的事情
you can "mock" some class so it look like a model but it does proxy to your APIs
f.e.
This may work.. but you need to do a lot django.model compatible stuff
django ORM 有一个可插入的后端,这意味着您可以为非 RDBMS 的事物编写后端。这可能是一项相当大的任务,但一个好的起点是 Malcolm Tredinnick 在 DjangoCon 2008 上的演讲,ORM 内部。
否则,您可以完全绕过 ORM,并手动编写表单以获得所需的访问权限。
The django ORM has a pluggable backent, which means that you can write a backend for things that aren't RDBMSes. It's probably a rather large task, but a good place to get started is with Malcolm Tredinnick's talk from DjangoCon 2008, Inside the ORM.
Otherwise, you could bypass the ORM altogether, and write the forms manually for the access you need.