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 1110747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:26:29+00:00 2026-05-17T02:26:29+00:00

In my django admin section, I’d like to show different versions of the admin

  • 0

In my django admin section, I’d like to show different versions of the admin page depending on what kind of user is currently logged in. I can think of a couple ways this might work, but haven’t figured out how to do any of them.

Perhaps I could put logic into the admin.ModelAdmin to look at the current user and change the ‘exclude’ field dynamically. Does that work? Or maybe run different custom templates based on who’s logged in, and have the templates include / exclude the fields as appropriate.

I could register two versions of the admin.ModelAdmin class, one for each type of user, and maybe restrict access through permissions? But the permissions system seems to believe fairly deeply in one set of permissions per model class so I’m not sure how to change that.

I could grab a couple of the widgets that are used in rendering the admin page templates, and include them in my own page that does the one specific job I need powerful users to be able to do.

I could set up multiple AdminSites and restrict access to them through the url / view system. But then I’m not sure how to register different admin.ModelAdmin classes with the different AdminSites.

Any advice on this would be appreciated.

Answer

Thanks for the hint. Here’s how I did it…

def get_form(self, request, obj=None, **kwargs):
    """This dynamically inserts the "owners" field into the exclude list
    if the current user is not superuser.
    """
    if not request.user.is_superuser:
        if self.exclude:
            self.exclude.append('owners')
        else:
            self.exclude = ['owners']
    else:
        # Necessary since Admin objects outlive requests
        try:
            self.exclude.remove('owners')
        except:
            pass


    return super(OwnersModelAdmin,self).get_form(request, obj=None, **kwargs)
  • 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-17T02:26:30+00:00Added an answer on May 17, 2026 at 2:26 am

    There are quite a few hooks provided in the ModelAdmin class for this sort of thing.

    One possibility would be to override the get_form method. This takes the request, as well as the object being edited, so you could get the current user from there, and return different ModelForms dependent on the user.

    It’s worth looking at the source for ModelAdmin – it’s in django.contrib.admin.options – to see if overriding this or any other other methods might meet your needs.

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

Sidebar

Related Questions

I am new to the Django framework. On Django's admin index page I'd like
The Django Admin page is different shades of blue by default. Where do I
how ill show in the admin section the user picture?, i was looking the
I overrided django admin login page and would like to pass some variables to
does ruby on rails have an Admin section generation feature like django?
I ran into a problem loading the admin section of my django site with
The Django admin site makes use of a really cool widget: How can I
Can Django admin site select entries by a custom date range, i.e. using two
I have FileField in my django model: file = models.FileField(upload_to=FOLDER_FILES_PATH) In Django admin section
I have a standard Django Admin page that is used to upload multiple files.

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.