from uuid import uuid4 from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver class Role(models.Model): """Extension of Django's built-in Group model Adds a UUID field to Django's built-in Group model. """ uuid = models.UUIDField( auto_created=True, default=uuid4, editable=False, help_text="object ID", primary_key=True, unique=True, ) group = models.OneToOneField(Group, on_delete=models.CASCADE) def __str__(self): return f"{self.group.name}" @receiver(post_save, sender=Group) def create_role(sender, instance, created, **kwargs): if created: Role.objects.create(group=instance)