Introspect object to be able to show table header even on empty object_list

This commit is contained in:
Roberto Rosario
2015-06-17 02:19:12 -04:00
parent 63201aa082
commit a7fd802436

View File

@@ -13,8 +13,20 @@ def object_property(value, arg):
@register.filter
def get_model_list_columns(obj):
try:
# Is it a query set?
obj = obj.model
except AttributeError:
# Is not a query set
try:
# Is iterable?
obj = obj[0]
except TypeError:
# It is not
pass
for key, value in model_list_columns.items():
if isinstance(obj, key):
if key == obj or isinstance(obj, key):
return value
return []