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

Commit

Permalink
Merge pull request #8 from alfa24/master
Browse files Browse the repository at this point in the history
handling the output of None fields
  • Loading branch information
linevych authored Apr 26, 2021
2 parents 2f4fd91 + c50cd4f commit 3b8207c
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 3b8207c

Please # to comment.