|
(I hate my email formatting) - - - - - - - - - - - - - - - - - - - - - - I asked too soon. Sorry. There is a method in contrib.admin.options.BaseModelAdmin called ... def has_delete_permission(self, request, obj=None):
"""
Returns True if the given request has permission to change the given
Django model instance, the default implementation doesn't examine the
`obj` parameter.
Can be overridden by the user in subclasses. In such case it should
return True if the given request has permission to delete the `obj`
model instance. If `obj` is None, this should return True if the given
request has permission to delete *any* object of the given type.
"""
opts = self.opts
codename = get_permission_codename('delete', opts)
return request.user.has_perm("%s.%s" % (opts.app_label, codename))
So I made a callable ... def see_delete(self, request, obj=None):
from django.contrib.auth import get_permission_codename
opts = self.opts
codename = get_permission_codename('delete', opts)
see = request.user.has_perm("%s.%s" % (opts.app_label, codename))
if obj:
if obj.company == get_user_company(request.user):
return see and True
else:
return False
return see
In myModelAdmin I put ... has_delete_permission = see_delete_buttonAnd it works nicely :) Open source is lovely and Django (and the Admin) is brilliant. I'm guessing showing the button disabled would be a CSS task which I don't have the brain-space for just now. Cheers Mike On 29/05/2019 8:37 am, Mike Dewhirst wrote: Django 1.11 and Python 3.6 but upgrading to Django 2.2 (slowly) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6b8ea3e3-3931-6274-c605-99622bedc6ef%40dewhirst.com.au. For more options, visit https://groups.google.com/d/optout. |
- How to disable the the Delete button Mike Dewhirst
- [Solved] How to disable the the Delete button Mike Dewhirst
- [Solved] How to disable the the Delete button Mike Dewhirst

