Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to omit object name from Django's TabularInline admin view?

I'm using Django's TabularInline admin view to edit category objects related to a main topic object, as shown here:

enter image description here

Is there a way to not show the rendered names of the objects ("General Questions", "Media Handling and Margins", etc. in this example), without creating a custom admin template? In other words, I just want to show a clean grid of input fields.

I found the relevant rendering code here, at this fragment:

   ...         <td class="original">           {% if inline_admin_form.original or inline_admin_form.show_url %}<p>           {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}           {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}             </p>{% endif %}    ... 

Is there a short, clever way to omit the {{ inline_admin_form.original }} or have it return Null?

like image 773
payne Avatar asked Feb 23 '11 02:02

payne


1 Answers

@sjaak-schilperoort Nice one! CSS is indeed the 'trick' to use. Example of the class Foo which has Bar as inline.

static/css/hide_admin_original.css:

td.original p {   visibility: hidden }  .inline-group .tabular tr.has_original td {     padding-top: 5px; } 

admin.py:

class FooAdmin(admin.ModelAdmin):   inlines = [ BarInline, ]   class Media:     css = { "all" : ("css/hide_admin_original.css",) }  admin.site.register(Foo, FooAdmin) 
like image 155
Rick van der Zwet Avatar answered Sep 20 '22 13:09

Rick van der Zwet