admin: only add link if function returns not None

This commit is contained in:
Jens Langhammer
2018-12-26 21:55:14 +01:00
parent 4d5f688a44
commit 0c9a00acbe
3 changed files with 88 additions and 77 deletions

View File

@ -18,9 +18,14 @@ def get_links(model_instance):
LOGGER.warning("Model %s is not instance of Model", model_instance)
return links
for name, method in inspect.getmembers(model_instance, predicate=inspect.ismethod):
if name.startswith(prefix):
human_name = name.replace(prefix, '').replace('_', ' ').capitalize()
links[human_name] = method()
try:
for name, method in inspect.getmembers(model_instance, predicate=inspect.ismethod):
if name.startswith(prefix):
human_name = name.replace(prefix, '').replace('_', ' ').capitalize()
link = method()
if link:
links[human_name] = link
except NotImplementedError:
pass
return links