#9360: Admin interface method get_form does not call get_fieldsets to get
fieldsets
--------------------------------------------------+-------------------------
Reporter: david_christiansen | Owner: nobody
Status: new | Milestone:
Component: django.contrib.admin | Version: 1.0
Keywords: fieldsets form modelform permissions | Stage: Unreviewed
Has_patch: 0 |
--------------------------------------------------+-------------------------
I'm presently limiting the fields that some users can edit in our admin
interface by defining two fieldsets variables and then overriding
get_fieldsets on the admin object to check for a user permission and
return the right fieldsets. It looks like this:
{{{
def get_fieldsets(self, request, obj=None):
if request.user.has_perm('page.can_change_structure'):
return self.fieldsets
else:
return self.fieldsets_content_only
}}}
However, the exluded fields were being set to blank whenever the form was
submitted by a user with fewer privileges. I tracked it down to the
get_form method of ModelAdmin. It gets the fieldsets as such: (starting
on line 777)
{{{
if self.declared_fieldsets:
fields = flatten_fieldsets(self.declared_fieldsets)
else:
fields = None
}}}
This ignores the get_fieldsets method. I'm not quite sure where the right
place to fix this is, so I haven't written a patch. For our use case, it
worked to simply override the get_form method and replace the four lines
above with:
{{{
fields = flatten_fieldsets(self.get_fieldsets(request, obj=obj))
}}}
Perhaps something similar would be the right solution overall?
We're running Django 1.0.
--
Ticket URL: <http://code.djangoproject.com/ticket/9360>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---