Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
handling the output of None fields
Browse files Browse the repository at this point in the history
  • Loading branch information
alfa24 committed Oct 8, 2020
1 parent bc2ca8a commit c50cd4f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion search_admin_autocomplete/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ def get_instance_name(self, instance: Model) -> str:
"""
Format instance name based on value of search fields.
"""
return ", ".join([getattr(instance, field) for field in self.search_fields])
values = []

for field in self.search_fields:
value = getattr(instance, field)
if not value:
continue
values.append(str(value))

if not values:
return ""

return ", ".join(values)

def get_instance_url(self, instance: Model) -> str:
"""
Expand Down

0 comments on commit c50cd4f

Please # to comment.