Django,如何生成没有模型的管理面板? [英] Django, how to generate an admin panel without models?

查看:100
本文介绍了Django,如何生成没有模型的管理面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个相当大的项目,其基本包括:

I'm building a rather large project, that basically consists of this:

服务器1:
基于Ice的服务。
冰川2用于会话处理。
允许访问Glacier2的防火墙。

Server 1: Ice based services. Glacier2 for session handling. Firewall allowing access to Glacier2.

服务器2:
通过Glacier2进行Ice服务的Web界面(读取,公开)。
通过冰川2的Ice服务的管理界面。

Server 2: Web interface (read, public) for Ice services via Glacier2. Admin interface for Ice services via Glacier 2.

我关心的是Web界面。我想使用Django,因为它都是用python编写的,具有非常实用的自动管理面板生成器。

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.

Web界面不访问任何数据库。它通过Glacier2路由器连接到服务器#1上的Ice服务,并使用这些服务公开的API来操纵数据。

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.

您可能知道,管理生成在Django中取决于使用Django的ORM;我没有使用,因为我没有数据库访问。

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.

所以我需要生成管理面板,但是,而不是像ORM这样的标准数据访问通常情况下,我需要拦截任何数据库访问调用并将其转换为Ice服务调用,然后将服务的输出(如果有的话)转换成ORM通常返回的任何值并将控制权返回给Django。

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?

感谢您的时间。

推荐答案

认为可能比编写自定义ORMS更简单的方法来获得所需的管理集成。我在一个允许通过控制面板API管理Webfaction电子邮件帐户的应用程序中使用它。

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.

查看models.py,admin.py和urls.py这里: django-webfaction

Take a look at models.py, admin.py and urls.py here: django-webfaction

要在管理员索引页面上创建一个条目,请使用具有managed = False的虚拟模型

To create an entry on the admin index page use a dummy model that has managed=False

使用管理员注册该模型。

Register that model with the admin.

然后,您可以拦截管理URL并将其引导至您自己的视图。

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

这篇关于Django,如何生成没有模型的管理面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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