Re: admin panel fieldsets for different type of users?
We've faced with same and other problems linked to the same issue. The idea is that DJango caches every object that's used in Admin. So, when you do exclude field, you should get it back to form in other cases. -- if not request.user.is_superuser: self.exclude.append('A') else: self.exclude.pop('A') -- The other universal solution is to reload admin class(es) everytime request is being processed. This will decrease speed, but no need to reenable & repopulate all data in admin models. Andrey > class CarsAdmin(admin.ModelAdmin): > fieldsets = (_('first group'},{'fields':(('A','B'),('C','D'),)}) > def get_form(self,request,obj=None, **kwargs): > self.exclude = [] > if not request.user.is_superuser: > self.exclude.append('A') > return super(CarAdmin,self).get_form(request, obj=None, **kwargs) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin panel fieldsets for different type of users?
Also wondering the exact same thing, so +1 on any pointers/hints/ help ... On Aug 1, 3:50 am, gondorwrote: > I use formset in my admin panel to group/title my related fields. > This works great except when I go to exclude some fields for lesser > users. > > In the simple example below if i'm a super user all works great. > If i log in as a staff user thus the code exclude A formset I get the > following error: > > Caught KeyError while rendering: Key 'A' not found in Form > > I don't mind having a conditional formset but I don't know how to do > that based on the type of user. Does anyone know how to solve this? > > model.py > > class Cars(models.Model): > A = models.CharField('A', ...) > B = models > C = models... > D = models... > > admin.py > > class CarsAdmin(admin.ModelAdmin): > fieldsets = (_('first group'},{'fields':(('A','B'),('C','D'),)}) > def get_form(self,request,obj=None, **kwargs): > self.exclude = [] > if not request.user.is_superuser: > self.exclude.append('A') > return super(CarAdmin,self).get_form(request, obj=None, **kwargs) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
admin panel fieldsets for different type of users?
I use formset in my admin panel to group/title my related fields. This works great except when I go to exclude some fields for lesser users. In the simple example below if i'm a super user all works great. If i log in as a staff user thus the code exclude A formset I get the following error: Caught KeyError while rendering: Key 'A' not found in Form I don't mind having a conditional formset but I don't know how to do that based on the type of user. Does anyone know how to solve this? model.py class Cars(models.Model): A = models.CharField('A', ...) B = models C = models... D = models... admin.py class CarsAdmin(admin.ModelAdmin): fieldsets = (_('first group'},{'fields':(('A','B'),('C','D'),)}) def get_form(self,request,obj=None, **kwargs): self.exclude = [] if not request.user.is_superuser: self.exclude.append('A') return super(CarAdmin,self).get_form(request, obj=None, **kwargs) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.