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): def get_context(self, context):
obj = resolve_attr_path(context, self.accessor) 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 { return {
**super().get_context(context), **super().get_context(context),
'title': self.title or title(obj._meta.verbose_name), 'title': title_,
'object': obj, 'object': obj,
} }

View File

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