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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:45:48+00:00 2026-05-24T04:45:48+00:00

In Django’s admin interface, there is a form, of a specific model that I

  • 0

In Django’s admin interface, there is a form, of a specific model that I want to be rendered in different ways depending if the logged user accessing this form is a normal user or an admin. It’s working find except one HUGE thing: it get’s mixed. For instance, the fields that should be editable by the admin are read-only, after I immediately prior to that had been logged in as a “normal” user. If I try the exactly same thing immediately after restarting the server, works fine and all fields are editable. I guess that somehow the user’s sessions are get mixed up. How to handle this?

Here is waht I have:

In the App’s admin.py:

151 class AdminForm(ModelForm):
152     class Meta:
153         model = PromotionalSlot
154         exclude = ['deal']
155 
156 class NormalUserForm(ModelForm):
157     class Meta:
158         model = PromotionalSlot
159         exclude = ['site']
160         
161 class PromotionalSlotAdmin(admin.ModelAdmin):
162      def get_form(self, request, obj=None, **kwargs):
163         if request.user.is_superuser:
164             return AdminForm
165         else:
166             self.readonly_fields = ['start_date','end_date','level','city','status']
167             return NormalUserForm· 
168
169 admin.site.register(models.PromotionalSlot, PromotionalSlotAdmin)

Thanks

  • 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-24T04:45:49+00:00Added an answer on May 24, 2026 at 4:45 am

    The problem is that your solution isn’t thread safe. Django keeps the admin instance around and so the value you set to self.readonly_fields is used also for all subsequent requests in the thread. This is how you can make it thread safe:

    class PromotionalSlotAdmin(admin.ModelAdmin):
    
        def get_readonly_fields(self, request, obj=None):
            if request.user.is_superuser:
                return []
            else:
                return ['start_date', 'end_date', 'level', 'city', 'status']
    
        def get_form(self, request, obj=None, **kwargs):
            if request.user.is_superuser:
                return AdminForm
            else:
                return NormalUserForm
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Django-admin is pluralizing a model that I have running as a proxy class. The
Django 1.1.1 Models.py: class Datapoint(models.Model): parameter1 = models.FloatField() parameter2 = models.FloatField() I want to
Django has the StackedInline-Feature for the Admin-Backend - is there any equivalent for django.forms?
Django view points to a function, which can be a problem if you want
(Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass
Django has a number of open source projects that tackle one of the framework's
Django is making very nice forms after creating a models.py and an admin.py. How
django.forms is very nice, and does almost exactly what I want to do on
Django seems to be falsely claiming that I have an error in my SQL
Django (1.2 beta) will reset the database(s) between every test that runs, meaning each

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.