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