Friday, October 29, 2010

Subclassing AdminSite

Hi, I must say I'm kinda lost here. Any help would greatly be
appreciated!

I wish to have two seperate admin sites on the same django project.

First thing I did, was create the app: alternate_admin
within alternate_admin, I have admin.py where I defined the following:

from django.contrib.admin.sites import AdminSite
class AltAdmin(AdminSite):
pass

alternate_admin = AltAdmin(name="Alternate Admin")

then at my project's root, in urls.py, I have:

from django.contrib import admin
from alternate_admin.admin import alternate_admin

...

admin.autodiscover()

urlpatterns = patterns('',
# Admin
(r'^admin/', include(admin.site.urls)),
(r'^',
include(alternate_admin.urls)),
# Sitemap
(r'^%s/' % settings.DAJAXICE_MEDIA_PREFIX,
include('dajaxice.urls')),
# Apps
(r'^profile/', include('profile.urls')),
url(r'^admin_tools/',
include('admin_tools.urls')),
(r'^account/',
include('django_authopenid.urls')),
(r'^trads/update/', 'trads.views.update'),
(r'^grappelli/',
include('grappelli.urls')),
)

I then proceed to register some admin models:

from alternate_admin.admin import alternate_admin

...

(my admin model def)

alternate_admin.register(MyModel, MyAdminModel)


Now if I try to log into the alternate admin as a super user, I can
log sucessfully but then I'm getting the "You don't have permission to
edit anything." message.

I checked the template and it seems this messages comes out when your
app_list is empty so I went and traced whether or not my models were
correctly registering with alternate_admin. At a first glance, they
indeed register but prior to the index loading, app_list is in fact
empty.

Then I noticed something odd with my urls.py:

If I replace:
(r'^', include(alternate_admin.urls)),

with
(r'^', include('alternate_admin.urls')),

and then go into alternate_admin/urls.py and enter:

from alternate_admin.admin import alternate_admin
patterns = alternate_admin.get_urls()

If I log into alternate_admin, I do see the apps containing the models
I registered.

Another strange thing (at least to me), is that if I inverse the urls
order
(r'^', include(alternate_admin.urls)),
(r'^admin/', include(admin.site.urls)),

I noticed that admin/ is not reachable anymore.

Perhaps my urls.py is messed up.

I'd really appreciate if someone can shed some light on this.

Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment