def METHOD_NAME(self, *args, **options):
    for group_name, content_types in SORTINGHAT_PERMISSION_GROUPS.items():
        new_group, created = Group.objects.using(options['database']).get_or_create(name=group_name)
        for app_label, models in content_types.items():
            for model, permissions in models.items():
                try:
                    content_type = ContentType.objects.using(options['database'])\
                                                      .get(app_label=app_label, model=model)
                    for permission_name in permissions:
                        codename = f"{permission_name}_{model}"
                        if model == "custompermissions":
                            codename = permission_name
                        try:
                            permission = Permission.objects.using(options['database'])\
                                                           .get(codename=codename, content_type=content_type)
                            new_group.permissions.add(permission)
                        except Permission.DoesNotExist:
                            logger.warning(f"Permission {permission_name} not found")
                            continue
                except ContentType.DoesNotExist:
                    logger.warning(f"ContentType {model} not found in {app_label}")
                    continue