views:

36

answers:

2

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

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

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.

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?

+1  A: 

You can subclass Django's AdminSite (put it eg. in admin.py in your project root):

from django.contrib.admin.sites import AdminSite

class MyAdminSite(AdminSite):
    pass
    #or overwrite some methods for different functionality

myadmin = MyAdminSite()

Then you can use it in your app's admin.py the same way as you do with the normal AdminSite instance:

from myproject.admin import myadmin
myadmin.register(MyModel_A)

You also need to define some urls for it (in your project's urls.py): from myproject.admin import admin, user_site

from myproject.admin import myadmin
urlpatterns = patterns('',
    ...
    (r'^admin/', include(admin.site.urls)),
    (r'^myadmin/', include(myadmin.urls)),

Also see this: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adminsite-objects

lazerscience
+1  A: 

To register models in different AdminSites you just need to create different instances of django.contrib.admin.sites.AdminSite, see http://docs.djangoproject.com/en/1.2/ref/contrib/admin/#adminsite-objects

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)

Claude Vedovini
when I try to do this, after I log in, I get the "You don't have permission to edit anything." message...
kender
The user you use should have the is_staff and is_superuser fields set to true. Then after to distinguish between different admin users and what they have access to see http://docs.djangoproject.com/en/1.2/topics/auth/#permissions
Claude Vedovini
Ok, I got this to work. But I can't seem to have a different set of templates for 2 admin sites - they both look up the 'admin/' directory in the templates, even one is created with 'backoffice' argument, which should set its name to 'backoffice'...
kender
Can you update the question and provide some code?
Claude Vedovini