Sunday, August 1, 2010

Does anyone know how to conditionally set the fieldsets??

I use fieldsets in my admin panel to group/title my related fields.
This works great in superuser. When I log in as staff, which has some
fields excluded I get an error.

Caught KeyError while rendering: Key 'A' not found in Form

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 fieldset I get the
the error:

models.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'sad('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)

Bottom line is I want to maintain the grouping offered by fieldsets.

Does anyone know how to conditionally set the fieldsets??

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment