Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3633596
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:40:23+00:00 2026-05-19T00:40:23+00:00

Apart from the usual admin, I want to create a limited admin for non-staff

  • 0

Apart from the usual admin, I want to create a limited admin for non-staff users. This admin site will have different registered ModelAdmins.

I created a folder /useradmin/ in my project directory and similar to contrib/admin/_init_.py I added an autodiscover() which will register models defined in useradmin.py modules instead of admin.py:

# useradmin/__init__.py
def autodiscover():
# Same as admin.autodiscover() but registers useradmin.py modules
...
for app in settings.INSTALLED_APPS:
    mod = import_module(app)
    try:
        before_import_registry = copy.copy(site._registry)
        import_module('%s.useradmin' % app)
    except:
        site._registry = before_import_registry
        if module_has_submodule(mod, 'useradmin'):
            raise

I also cretated sites.py under useradmin/ to override AdminSite similar to contrib/admin/sites:

# useradmin/sites.py
class UserAdminSite(AdminSite):
    def has_permission(self, request):
        # Don't care if the user is staff
        return request.user.is_active

    def login(self, request):
        # Do the login stuff but don't care if the user is staff
        if request.user.is_authenticated():
            ...
        else:
            ...

site = UserAdminSite(name='useradmin')

In the project’s URLs:

# urls.py
from django.contrib import admin
import useradmin

admin.autodiscover()
useradmin.autodiscover()

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^useradmin/', include(useradmin.site.urls)),
)

And I try to register different models in admin.py and useradmin.py modules under app directories:

# products/useradmin.py
import useradmin
class ProductAdmin(useradmin.ModelAdmin):
    pass
useradmin.site.register(Product, ProductAdmin)

But when registering models in useradmin.py like useradmin.site.register(Product, ProductAdmin), I get 'module' object has no attribute 'ModelAdmin' exception. Though when I try this via shell;

import useradmin
from useradmin import ModelAdmin

does not raise any exception.

Any ideas what might be wrong?

Edit:

I tried going the @Luke way and arranged the code as follows as minimal as possible:
(file paths are relative to the project root)

# admin.py
from django.contrib.admin import autodiscover
from django.contrib.admin.sites import AdminSite
user_site = AdminSite(name='useradmin')

# urls.py (does not even have url patterns; just calls autodiscover())
import admin
admin.autodiscover()

# products/admin.py
import admin
from products.models import Product
admin.user_site.register(Product)

As a result I get an AttributeError: 'module' object has no attribute 'user_site' when admin.user_site.register(Product) in products/admin.py is called.

Any ideas?

Solution:

I don’t know if there are better ways but, renaming the admin.py in the project root to useradmin.py and updating the imports accordingly resolved the last case, which was a naming and import conflict.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:40:23+00:00Added an answer on May 19, 2026 at 12:40 am

    Does useradmin have a ModelAdmin class defined, or do you import it from contrib.admin? I don’t see anywhere in the code you supplied where that class gets set up.

    That being said, there’s a much easier way to do this: just initialize two AdminSites, and then wire them up to the URLs that you want (You can even put them in the same urlconf).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apart from C++, which non-toy languages have direct or easy-to-use compatibility to C? As
There exist other ways of linking to JS, apart from this (the usual).. <script
On all pages apart from the contact page, I want it to show the
I want to implement two features apart from the ones in Basic View of
I have a table with three columns (apart from the id): topic user ip
I have the following code which works from my 'scorer' class apart from in
Apart from unambiguous clarity, why should we stick to: car.getSpeed() and car.setSpeed(55) when this
Apart from being non persistent and scoped only to the current window, are there
I'm testing AES encryption functions from this example . I have found that If
What is the point of a non-blocking bookmark (apart from it being non-blocking and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.