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):
|
70 | 70 | |
71 | 71 | Three basic permissions -- add, change and delete -- are automatically created for each Django model. |
72 | 72 | """ |
73 | | name = models.CharField(_('name'), max_length=50) |
| 73 | name = models.CharField(_('name'), max_length=100) |
74 | 74 | content_type = models.ForeignKey(ContentType) |
75 | 75 | codename = models.CharField(_('codename'), max_length=100) |
76 | 76 | |
… |
… |
class User(models.Model):
|
146 | 146 | class Meta: |
147 | 147 | verbose_name = _('user') |
148 | 148 | verbose_name_plural = _('users') |
149 | | ordering = ('username',) |
| 149 | ordering = ('last_name', 'first_name', 'username') |
150 | 150 | |
151 | 151 | class Admin: |
152 | 152 | fields = ( |
… |
… |
class User(models.Model):
|
161 | 161 | search_fields = ('username', 'first_name', 'last_name', 'email') |
162 | 162 | |
163 | 163 | 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 |
165 | 172 | |
166 | 173 | def get_absolute_url(self): |
167 | 174 | return "/users/%s/" % urllib.quote(smart_str(self.username)) |