I want to collects current user in model signal pre_save, to prevent remove
super user permission to current super users.
As I have now so I can not give administrative privileges to a normal user.
from django.db.models.signals import pre_delete, pre_save, post_save
from django.dispatch.dispatcher import receiver
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
@receiver(pre_save, sender=User)
def save_user(sender, instance, **kwargs):
if instance._state.adding is True:
# we would need to create the object
print "Creating an object"
else:
#we are updating the object
if instance.is_superuser:
raise PermissionDenied
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" 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 http://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/1b710450-6d76-46ce-a8bf-1a0a49c55cf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.