[Answered ]-Django User's Sessions getting Mixed.

2👍

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

Leave a comment