Introspect object to be able to show table header even on empty object_list
This commit is contained in:
@@ -13,8 +13,20 @@ def object_property(value, arg):
|
|||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def get_model_list_columns(obj):
|
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():
|
for key, value in model_list_columns.items():
|
||||||
if isinstance(obj, key):
|
if key == obj or isinstance(obj, key):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
|||||||
Reference in New Issue
Block a user