From f3cc2d16796b95575c6972250c171a501eb9fa05 Mon Sep 17 00:00:00 2001 From: Fer-Bar Date: Thu, 23 May 2024 19:40:10 -0400 Subject: [PATCH] Added picture_url property to return safe url strings --- people/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/people/models.py b/people/models.py index 4534dfe..886eca9 100644 --- a/people/models.py +++ b/people/models.py @@ -145,6 +145,15 @@ class Person(models.Model): help_text=_("Max size allowed: 20Mbs"), ) + @property + def picture_url(self): + """ + Return self.picture.url if self.picture is not None, + 'url' exist and has a value, else, return None. + """ + if self.picture and hasattr(self.picture, "url"): + return self.picture.url + def create_user(self): if self.user_id is not None: return