Skip to content

Commit

Permalink
patch: case user has no user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
tinashechiraya authored Mar 5, 2024
1 parent ebdfd2e commit a719fcc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions django_project/monitor/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
Expand Down

0 comments on commit a719fcc

Please sign in to comment.