Skip to content

Commit

Permalink
Merge pull request #53 from Anton-Shutik/master
Browse files Browse the repository at this point in the history
Do not return prepopulated fields for view only users
  • Loading branch information
lefterisnik committed Aug 8, 2018
2 parents 0699905 + e92445c commit 2af8b42
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions admin_view_permission/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@ 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 fails when creating a form
"""
is_add = obj is None and self.has_add_permission(request)
is_change = obj is not None \
and self._has_change_only_permission(request, obj)
if is_add or is_change:
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 2af8b42

Please sign in to comment.