Reputation: 6858
When I create a TabularInline in my Django's admin panel, it displays a title per record. How can I change this title? How can I delete this title?
I include a screenshot below. The title I am referring to is here ExportLookupTableElement object. The lines without that title are the extra fields to add new ones. I want the entire table to look like this.
Upvotes: 6
Views: 5179
Reputation: 370
Based on nattster's answer I did this:
edit/create templates/admin/base_site.html
:
{% extends "admin/base.html" %}
{% block extrastyle %}
<link rel="stylesheet" href="{% static "admin/css/admin_overrides.css" %}" />
{% endblock %}
create admin/css/admin_overrides.css
:
/* StackedInline */
.inline-group .hide-title h3 b, .inline-group .hide-title h3 .inline_label {
visibility: hidden;
}
/* TabularInline */
.inline-group .tabular .hide-title .original > p {
display: none;
}
.inline-group .tabular .hide-title tr.has_original td {
padding-top: 8px;
}
Now you can hide the title for some inlines while keep it for others:
class TestTabularInline(admin.TabularInline):
classes = ("hide-title",)
...
class TestStackedInline(admin.StackedInline):
classes = ("hide-title",)
...
Upvotes: 1
Reputation: 1
If you can afford it for the purposes of your inlined model, returning an empty string from its __str__
method has exactly the same effect as solutions provided above. The title element is still in the HTML, but no longer takes up any visible space.
class TestDetail(models.Model):
...
def __str__(self):
return ''
Upvotes: -2
Reputation: 854
You can remove this title by overriding Django's admin css:
css/custom_admin.css
in your static directory with following code:.inline-group .tabular tr.has_original td {
padding-top: 8px;
}
.original {
display: none;
}
admin.py
file to include this extra css for ModelAdmin that you want to remove title:class TestDetailInline(admin.TabularInline):
model = TestDetail
class TestAdmin(admin.ModelAdmin):
class Media:
css = {
'all': ('css/custom_admin.css', ) # Include extra css
}
inlines = [TestDetailInline]
Or you can override css for all admin pages by following this answer.
Upvotes: 14