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