Skip to content

Commit

Permalink
Do not return prepopulated fields for view only users
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-Shutik committed Jul 26, 2018
1 parent ea90d5b commit 3860f40
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions admin_view_permission/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ def get_readonly_fields(self, request, obj=None):

return tuple(readonly_fields)

def get_prepopulated_fields(self, request, obj=None):
"""
If user has view only permission do not return any prepopulated configuration,
since it failes when creating a form
"""
if (obj is None and self.has_add_permission(request)) or \
(obj is not None and self._has_change_only_permission(request, obj)):
return super(AdminViewPermissionBaseModelAdmin, self).get_prepopulated_fields(request, obj)
return {}

def get_actions(self, request):
"""
Override this funciton to remove the actions from the changelist view
Expand Down

0 comments on commit 3860f40

Please sign in to comment.