Ticket #13914: contrib_auth_user_group_natural_key.patch

File contrib_auth_user_group_natural_key.patch, 1.8 KB (added by Juarez Bochi, 14 years ago)
  • django/contrib/auth/models.py

     
    8484        return (self.codename,) + self.content_type.natural_key()
    8585    natural_key.dependencies = ['contenttypes.contenttype']
    8686
     87class GroupManager(models.Manager):
     88    def get_by_natural_key(self, name):
     89        return self.get(name=name)
     90
    8791class Group(models.Model):
    8892    """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.
    8993
     
    9397    """
    9498    name = models.CharField(_('name'), max_length=80, unique=True)
    9599    permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True)
     100    objects = GroupManager()
    96101
    97102    class Meta:
    98103        verbose_name = _('group')
     
    101106    def __unicode__(self):
    102107        return self.name
    103108
     109    def natural_key(self):
     110        return (self.name,)
     111
    104112class UserManager(models.Manager):
    105113    def create_user(self, username, email, password=None):
    106114        """
     
    144152        from random import choice
    145153        return ''.join([choice(allowed_chars) for i in range(length)])
    146154
     155    def get_by_natural_key(self, username):
     156        return self.get(username=username)
    147157
     158
    148159# A few helper functions for common logic between User and AnonymousUser.
    149160def _user_get_all_permissions(user, obj):
    150161    permissions = set()
     
    381392        return self._message_set
    382393    message_set = property(_get_message_set)
    383394
     395    def natural_key(self):
     396        return (self.username,)
     397
    384398class Message(models.Model):
    385399    """
    386400    The message system is a lightweight way to queue messages for given
Back to Top