summaryrefslogtreecommitdiff
path: root/django/contrib/auth
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-12-14 12:39:20 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-12-14 12:39:20 +0000
commit35cc439228cd32dfa7a3ec919db01a8a5cd17d33 (patch)
treeed9aff433487895c0e649994450fd0accb6362d2 /django/contrib/auth
parent44b9076bbed3e629230d9b77a8765e4c906036d1 (diff)
Fixed #7052 -- Added support for natural keys in serialization.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11863 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/auth')
-rw-r--r--django/contrib/auth/models.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index 053761cb56..b20a2caf17 100644
--- a/django/contrib/auth/models.py
+++ b/django/contrib/auth/models.py
@@ -47,6 +47,13 @@ def check_password(raw_password, enc_password):
class SiteProfileNotAvailable(Exception):
pass
+class PermissionManager(models.Manager):
+ def get_by_natural_key(self, codename, app_label, model):
+ return self.get(
+ codename=codename,
+ content_type=ContentType.objects.get_by_natural_key(app_label, model)
+ )
+
class Permission(models.Model):
"""The permissions system provides a way to assign permissions to specific users and groups of users.
@@ -63,6 +70,7 @@ class Permission(models.Model):
name = models.CharField(_('name'), max_length=50)
content_type = models.ForeignKey(ContentType)
codename = models.CharField(_('codename'), max_length=100)
+ objects = PermissionManager()
class Meta:
verbose_name = _('permission')
@@ -76,6 +84,10 @@ class Permission(models.Model):
unicode(self.content_type),
unicode(self.name))
+ def natural_key(self):
+ return (self.codename,) + self.content_type.natural_key()
+ natural_key.dependencies = ['contenttypes.contenttype']
+
class Group(models.Model):
"""Groups are a generic way of categorizing users to apply permissions, or some other label, to those users. A user can belong to any number of groups.