[PATCH 2/7] models: Monkey patch User to have a name() method

Damien Lespiau damien.lespiau at intel.com
Wed Oct 21 09:40:42 AEDT 2015


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 at intel.com>
---
 patchwork/models.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/patchwork/models.py b/patchwork/models.py
index a1d6840..8a0858b 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -20,6 +20,7 @@
 from django.db import models
 from django.db.models import Q
 import django.dispatch
+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
@@ -86,6 +87,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)
-- 
2.4.3



More information about the Patchwork mailing list