Skip to content

Management commands

Command

Bases: BaseCommand

A wrapper around guardian.utils.clean_orphan_obj_perms.

Seeks and removes all object permissions entries pointing at non-existing targets. Returns the number of objects removed.

Example
$ python manage.py clean_orphan_obj_perms
Removed 11 object permission entries with no targets
Source code in guardian/management/commands/clean_orphan_obj_perms.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Command(BaseCommand):
    """A wrapper around `guardian.utils.clean_orphan_obj_perms`.

    Seeks and removes all object permissions entries pointing at non-existing targets.
    Returns the number of objects removed.

    Example:
        ```shell
        $ python manage.py clean_orphan_obj_perms
        Removed 11 object permission entries with no targets
        ```
    """
    help = "Removes object permissions with not existing targets"

    def handle(self, **options):
        removed = clean_orphan_obj_perms()
        if options['verbosity'] > 0:
            print("Removed %d object permission entries with no targets" %
                  removed)