[PATCH 15/51] models: Monkey patch User to have a name() method
Damien Lespiau
damien.lespiau at intel.com
Sat Sep 12 01:54:48 AEST 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 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)
--
2.1.0
More information about the Patchwork
mailing list