From a719fcccab157a2b28acd86ab70e2027fc75ff4e Mon Sep 17 00:00:00 2001 From: Tinashe <70011086+tinashechiraya@users.noreply.github.com> Date: Tue, 5 Mar 2024 08:07:17 +0200 Subject: [PATCH] patch: case user has no user profile --- django_project/monitor/admin.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/django_project/monitor/admin.py b/django_project/monitor/admin.py index c5ca718db..af4439779 100644 --- a/django_project/monitor/admin.py +++ b/django_project/monitor/admin.py @@ -180,6 +180,7 @@ class SitesAdmin(admin.ModelAdmin): list_max_show_all = 1000 list_display = ( 'site_name', + 'river_name', 'user', 'user_organization_name', 'user_country', @@ -188,13 +189,16 @@ class SitesAdmin(admin.ModelAdmin): ) def user_organization_name(self, obj): - return obj.user.userprofile.organisation_name + user_profile = obj.user.userprofile if hasattr(obj.user, 'userprofile') else None + return user_profile.organisation_name if user_profile else None def user_country(self, obj): - return obj.user.userprofile.country + user_profile = obj.user.userprofile if hasattr(obj.user, 'userprofile') else None + return user_profile.country if user_profile else None def user_is_expert(self, obj): - return obj.user.userprofile.is_expert + user_profile = obj.user.userprofile if hasattr(obj.user, 'userprofile') else None + return user_profile.is_expert if user_profile else None user_organization_name.short_description = 'User Organization Name' user_country.short_description = 'User Country'