diff mbox

[15/51] models: Monkey patch User to have a name() method

Message ID 1441986924-26689-16-git-send-email-damien.lespiau@intel.com
State Superseded
Headers show

Commit Message

Damien Lespiau Sept. 11, 2015, 3:54 p.m. UTC
The name is really a poperty of the User. Not always having to retrieve
the profile for that makes things simpler.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 patchwork/models.py | 3 +++
 1 file changed, 3 insertions(+)
diff mbox

Patch

diff --git a/patchwork/models.py b/patchwork/models.py
index 1990989..1f13722 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -19,6 +19,7 @@ 
 
 from django.db import models
 from django.db.models import Q
+from django.contrib import auth
 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 from django.contrib.sites.models import Site
@@ -84,6 +85,8 @@  def user_name(user):
         return u' '.join(names)
     return user.username
 
+auth.models.User.add_to_class('name', user_name)
+
 class UserProfile(models.Model):
     user = models.OneToOneField(User, unique = True, related_name='profile')
     primary_project = models.ForeignKey(Project, null = True, blank = True)