Ticket #13914: contrib_auth_user_group_natural_key.patch
File contrib_auth_user_group_natural_key.patch, 1.8 KB (added by , 14 years ago) |
---|
-
django/contrib/auth/models.py
84 84 return (self.codename,) + self.content_type.natural_key() 85 85 natural_key.dependencies = ['contenttypes.contenttype'] 86 86 87 class GroupManager(models.Manager): 88 def get_by_natural_key(self, name): 89 return self.get(name=name) 90 87 91 class Group(models.Model): 88 92 """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. 89 93 … … 93 97 """ 94 98 name = models.CharField(_('name'), max_length=80, unique=True) 95 99 permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True) 100 objects = GroupManager() 96 101 97 102 class Meta: 98 103 verbose_name = _('group') … … 101 106 def __unicode__(self): 102 107 return self.name 103 108 109 def natural_key(self): 110 return (self.name,) 111 104 112 class UserManager(models.Manager): 105 113 def create_user(self, username, email, password=None): 106 114 """ … … 144 152 from random import choice 145 153 return ''.join([choice(allowed_chars) for i in range(length)]) 146 154 155 def get_by_natural_key(self, username): 156 return self.get(username=username) 147 157 158 148 159 # A few helper functions for common logic between User and AnonymousUser. 149 160 def _user_get_all_permissions(user, obj): 150 161 permissions = set() … … 381 392 return self._message_set 382 393 message_set = property(_get_message_set) 383 394 395 def natural_key(self): 396 return (self.username,) 397 384 398 class Message(models.Model): 385 399 """ 386 400 The message system is a lightweight way to queue messages for given