Ticket #6491: 0019-Improvements-to-User-and-Permission-models.patch

File 0019-Improvements-to-User-and-Permission-models.patch, 1.9 KB (added by Bastian Kleineidam <calvin@…>, 17 years ago)
  • django/contrib/auth/models.py

    From 589a7bafdd4b4d23814322b2fb546ab6d28f0361 Mon Sep 17 00:00:00 2001
    From: Bastian Kleineidam <calvin@debian.org>
    Date: Fri, 25 Jan 2008 21:21:24 +0100
    Subject: Improvements to User and Permission models
    
    The Permission model increases the maximal permission name length
    from 50 to 100 (I actually hit this limit with some model permission
    names some of my projects).
    The User model will be sorted by last name, first name and then
    username. And the string representation of a user will include the
    last and first name if defined.
    
    Signed-off-by: Bastian Kleineidam <calvin@debian.org>
    
    diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
    index 4b15902..29d588c 100644
    a b class Permission(models.Model):  
    7070
    7171    Three basic permissions -- add, change and delete -- are automatically created for each Django model.
    7272    """
    73     name = models.CharField(_('name'), max_length=50)
     73    name = models.CharField(_('name'), max_length=100)
    7474    content_type = models.ForeignKey(ContentType)
    7575    codename = models.CharField(_('codename'), max_length=100)
    7676
    class User(models.Model):  
    146146    class Meta:
    147147        verbose_name = _('user')
    148148        verbose_name_plural = _('users')
    149         ordering = ('username',)
     149        ordering = ('last_name', 'first_name', 'username')
    150150
    151151    class Admin:
    152152        fields = (
    class User(models.Model):  
    161161        search_fields = ('username', 'first_name', 'last_name', 'email')
    162162
    163163    def __unicode__(self):
    164         return self.username
     164        if self.last_name:
     165            s = self.last_name
     166            if self.first_name:
     167                s += ", %s" % self.first_name
     168            s += " (%s)" % self.username
     169        else:
     170            s = self.username
     171        return s
    165172
    166173    def get_absolute_url(self):
    167174        return "/users/%s/" % urllib.quote(smart_str(self.username))
Back to Top