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

  • Home
  • SEARCH
  • 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 173507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:21:22+00:00 2026-05-11T13:21:22+00:00

I’ve tried various methods to achieve this. I decided against overriding formfield_for_dbfield as it

  • 0

I’ve tried various methods to achieve this.

I decided against overriding formfield_for_dbfield as it doesn’t get a copy of the request object and I was hoping to avoid the thread_locals hack.

I settled on overriding get_form in my ModelAdmin class and tried the following:

class PageOptions(admin.ModelAdmin):     def get_form(self, request, obj=None, **kwargs):         if request.user.is_superuser:             self.fieldsets = ((None, {'fields': ('title','name',),}),)         else:             self.fieldsets = ((None, {'fields': ('title',),}),)         return super(PageOptions,self).get_form(request, obj=None, **kwargs) 

When I print fieldsets or declared_fieldsets from within get_form I get None (or whatever I set as an initial value in PageOptions).

Why doesn’t this work and is there a better way to do this?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T13:21:23+00:00Added an answer on May 11, 2026 at 1:21 pm

    I have no idea why printing the property doesn’t give you want you just assigned (I guess may be that depends on where you print, exactly), but try overriding get_fieldsets instead. The base implementation looks like this:

    def get_fieldsets(self, request, obj=None):     if self.declared_fieldsets:         return self.declared_fieldsets     form = self.get_formset(request).form     return [(None, {'fields': form.base_fields.keys()})] 

    I.e. you should be able to just return your tuples.

    EDIT by andybak. 4 years on and I found my own question again when trying to do something similar on another project. This time I went with this approach although modified slightly to avoid having to repeat fieldsets definition:

    def get_fieldsets(self, request, obj=None):     # Add 'item_type' on add forms and remove it on changeforms.     fieldsets = super(ItemAdmin, self).get_fieldsets(request, obj)     if not obj: # this is an add form         if 'item_type' not in fieldsets[0][1]['fields']:             fieldsets[0][1]['fields'] += ('item_type',)     else: # this is a change form         fieldsets[0][1]['fields'] = tuple(x for x in fieldsets[0][1]['fields'] if x!='item_type')     return fieldsets 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

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.