@@ -38,12 +38,15 @@ class Person(models.Model):
user = models.ForeignKey(User, null = True, blank = True,
on_delete = models.SET_NULL)
- def __unicode__(self):
+ def display_name(self):
if self.name:
return self.name
else:
return self.email
+ def __unicode__(self):
+ return self.display_name()
+
def link_to_user(self, user):
self.name = user.profile.name()
self.user = user
@@ -33,7 +33,7 @@ class ProjectSerializer(serializers.HyperlinkedModelSerializer):
'webscm_url')
class SeriesSerializer(serializers.ModelSerializer):
- submitter__name = serializers.CharField(source='submitter.name',
+ submitter__name = serializers.CharField(source='submitter.display_name',
read_only=True)
reviewer__name = serializers.CharField(source='reviewer.name',
read_only=True)
submitter.name can be null when mails are sent with a From: field populated with just an email address. Present something displayable in the API. Signed-off-by: Damien Lespiau <damien.lespiau@intel.com> --- patchwork/models.py | 5 ++++- patchwork/serializers.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-)