Handle panel title when object is not available

This commit is contained in:
Jeremy Stretch
2026-04-02 11:15:08 -04:00
parent aeef559c0b
commit 468dd84027
2 changed files with 19 additions and 11 deletions

View File

@@ -106,9 +106,15 @@ class ObjectPanel(Panel):
def get_context(self, context):
obj = resolve_attr_path(context, self.accessor)
if self.title is not None:
title_ = self.title
elif obj is not None:
title_ = title(obj._meta.verbose_name)
else:
title_ = None
return {
**super().get_context(context),
'title': self.title or title(obj._meta.verbose_name),
'title': title_,
'object': obj,
}

View File

@@ -1,15 +1,17 @@
<!-- begin {{ panel_class|default:"panel" }} -->
<div class="card">
<h2 class="card-header">
{{ title }}
{% if actions %}
<div class="card-actions">
{% for action in actions %}
{% render action %}
{% endfor %}
</div>
{% endif %}
</h2>
{% if title or actions %}
<h2 class="card-header">
{{ title|default:"" }}
{% if actions %}
<div class="card-actions">
{% for action in actions %}
{% render action %}
{% endfor %}
</div>
{% endif %}
</h2>
{% endif %}
{% block panel_content %}{% endblock %}
</div>
<!-- end {{ panel_class|default:"panel" }} -->