MCPcopy
hub / github.com/django/django / Permission

Class Permission

django/contrib/auth/models.py:39–90  ·  view source on GitHub ↗

The permissions system provides a way to assign permissions to specific users and groups of users. The permission system is used by the Django admin site, but may also be useful in your own code. The Django admin site uses permissions as follows: - The "add" permission lim

Source from the content-addressed store, hash-verified

37
38
39class Permission(models.Model):
40 """
41 The permissions system provides a way to assign permissions to specific
42 users and groups of users.
43
44 The permission system is used by the Django admin site, but may also be
45 useful in your own code. The Django admin site uses permissions as follows:
46
47 - The "add" permission limits the user's ability to view the "add" form
48 and add an object.
49 - The "change" permission limits a user's ability to view the change
50 list, view the "change" form and change an object.
51 - The "delete" permission limits the ability to delete an object.
52 - The "view" permission limits the ability to view an object.
53
54 Permissions are set globally per type of object, not per specific object
55 instance. It is possible to say "Mary may change news stories," but it's
56 not currently possible to say "Mary may change news stories, but only the
57 ones she created herself" or "Mary may only change news stories that have a
58 certain status or publication date."
59
60 The permissions listed above are automatically created for each model.
61 """
62
63 name = models.CharField(_("name"), max_length=255)
64 content_type = models.ForeignKey(
65 ContentType,
66 models.CASCADE,
67 verbose_name=_("content type"),
68 )
69 codename = models.CharField(_("codename"), max_length=100)
70
71 objects = PermissionManager()
72
73 class Meta:
74 verbose_name = _("permission")
75 verbose_name_plural = _("permissions")
76 unique_together = [["content_type", "codename"]]
77 ordering = ["content_type__app_label", "content_type__model", "codename"]
78
79 def __str__(self):
80 return "%s | %s" % (self.content_type, self.name)
81
82 @property
83 def user_perm_str(self):
84 """String representation for the user permission check."""
85 return f"{self.content_type.app_label}.{self.codename}"
86
87 def natural_key(self):
88 return (self.codename, *self.content_type.natural_key())
89
90 natural_key.dependencies = ["contenttypes.contenttype"]
91
92
93class GroupManager(models.Manager):

Callers 1

create_permissionsFunction · 0.85

Calls 1

PermissionManagerClass · 0.85

Tested by

no test coverage detected