from django.db.models import Sum
from apps.authorization.models import Role, UserRelations
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver


# @receiver([post_save], sender=UserRelations)
# def sync_role_permissions(sender, instance, **kwargs):
#     """ add role permissions to user relation permissions in is null """
#
#     # if _from_signal=True prevent from maximum recursion loop
#     if getattr(instance, '_from_signal', False):
#         return
#
#     if instance.role:
#         permissions = instance.role.permissions.all()
#     if not instance.permissions.exists():
#         instance.permissions.add(*permissions)  # noqa
#
#     instance._from_signal = True
#     instance.save()





