Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django, how to generate an admin panel without models?

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.

like image 204
user168833 Avatar asked Nov 28 '09 20:11

user168833


2 Answers

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

like image 75
Andy Baker Avatar answered Sep 22 '22 07:09

Andy Baker


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.

like image 24
T. Stone Avatar answered Sep 23 '22 07:09

T. Stone