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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:47:38+00:00 2026-06-08T21:47:38+00:00

I have several very customized Django ModelAdmins that I would like to add extra

  • 0

I have several very customized Django ModelAdmins that I would like to add extra field(s) if the user is a superuser. I found somewhere that someone said to override the get_fieldsets method like this

def get_fieldsets(self, request, obj=None):
    fieldsets = super(PageAdmin, self).get_fieldsets(request, obj)
    if request.user.is_superuser:
        fieldsets[0][1]['fields'].insert(0,'group')
        fieldsets[0][1]['fields'].insert(2,'is_live')
    else:
        groups = request.user.page_groups.filter(
            is_live = True,
        )
        if groups.count() > 1:
            fieldsets[0][1]['fields'].insert(0,'group')
    return fieldsets

This works (sort of) and I like using get_fieldsets because it lets me group the fields into fieldsets.
I also use get_form on this admin because the form has several user specific form fields that have querysets based on the user.

def get_form(self, request, obj=None, **kwargs):
    if request.user.is_superuser:
        return PageForm
    else:
        form = RestrictedPageForm
        form.owner = request.user #(this may be a bad way to do this but it works I think)
        return form

Now I am running into what I believe to be Threading issues.

What happens is that if you quickly refresh the change_form page in the browser you will see multiple “group” or “is_live” fields in the form.

I have really liked leveraging the Admin to keep me from having to write everything but I cannot find out how to do this correctly. Any help or suggestions would be greatly appreciated!

  • 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-06-08T21:47:40+00:00Added an answer on June 8, 2026 at 9:47 pm

    The problem is that you’re literally changing the fieldsets attribute on the ModelAdmin, which is not thread-safe, even though get_fieldsets is.

    The best way to do this is to specify separate fieldsets:

    fieldsets = (...)
    restricted_fieldsets = (...)
    

    Then:

    def get_fieldsets(self, request, obj=None):
        if some_condition:
            return self.restricted_fieldsets
        else:
            return super(MyModelAdmin, self).get_fieldsets(request, obj=obj)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several folders with some files that I would like to rename from
I have several database tables that just contain a single column and very few
I have several different numbers in a group that range in sizes and would
I have several reports that all merge onto the same datatable. The user can
I have several <xsl:for-each/> which run the one after the other. I would like,
I have a several very expensive queries which seem to hog resources that seems
In my MS Access application I have several forms that are very data intensive
I have several pages that are all very similar. They have some javascript rollover
I have a c++ program that uses several very large arrays of doubles, and
I have a SOLR index over several million full text documents. This works very

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.