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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:58:54+00:00 2026-05-28T17:58:54+00:00

I have a modified admin form, where I added a field that shall modify

  • 0

I have a modified admin form, where I added a field that shall modify the values of the current model’s parent object. Now, depending on the user, I need to

  • alter the queryset of that extra field
  • set another field as readonly (or better, even hide it completely)

Basically my code below works as I’d expect it. A superuser gets the whole queryset and the other field is not readonly. All other users get a limited queryset and the other field is readonly. However, once I open that site in a different browser and as a non-superuser, even the superuser get the same result as the non-superusers. Seems like django somehow caches the result? If I put some print statements inside the conditional branches though, they get printed correctly. So the method still gets called each time and seems to still perform these steps. Only with a wrong outcome.

Is that a caching problem? Am I doing something entirely wrong? Can it be a bug in the django test server?

def get_form(self, request, obj=None, **kwargs):
    form = super(MultishopProductAdmin, self).get_form(request, obj, **kwargs)
    if obj is not None:
        form.declared_fields['categories'].initial = obj.product.category.all()
    if not request.user.is_superuser:
        user_site = request.user.get_profile().site
        form.declared_fields['categories'].queryset = Category.objects.filter(site__id=user_site.id)
        self.readonly_fields = ('virtual_sites', )
        if obj is not None:
            form.declared_fields['categories'].initial = obj.product.category.filter(site__id=user_site.id)
    return form
  • 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-28T17:58:55+00:00Added an answer on May 28, 2026 at 5:58 pm

    So I couldn’t find a really clever way to do what I wanted with django admin’s custom methods. What I ended up doing now is implementing the admin’s change_view, setting up my own form manually and performing all my custom initializations from there.

    I then provided a custom template by setting change_form_template, which is simply extending admin/change_form.html but rendering my own form instead of the default one. I also set extra_context['adminform'] = None so the default admin form gets removed.

    That way I can now customize my form the way I need it to be but still use all the other admin conveniences. So far it seems to work very nicely. Not the very most elegant solution either I think, but the best I could think of.

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

Sidebar

Related Questions

I have an InfoPath 2007 form that I am publishing to a Central Admin
I have modified a working Windows service that had always been starting beforehand. After
I have a dataset that I have modified into an xml document and then
I have an XML object (loaded using XMLHTTPRequest 's responseXML ). I have modified
I have this sample model working with the admin class Author(models.Model): name = models.CharField(_('Text
I have modified my etc/hosts file (under Windows 7), so that www.example.com and demo.example.com
I have a standard Django Admin page that is used to upload multiple files.
I have a django model called Blog . I'd like to add a field
I have modified the buddypress admin bar by creating the following plugin which adds
I have developed a site in drupal 7 and forget its admin password. Now

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.