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

django admin
django get_form
django admin template
django admin dashboard
django admin permissions
django admin many to-many
django admin custom form
django admin panel customization

I'm using Django's TabularInline admin view to edit category objects related to a main topic object, as shown 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?

I thought I'd chime in that editing your template is going to be the easiest.

I tried iterating over the formsets in render_change_form but unfortunately, the major problem is that InlineAdminForms are constructed dynamically upon iteration in the template so you can't just set inlineadminform.original = None or modify the context.

They don't even exist until assigned a variable in the template.

# InlineAdminFormset
def __iter__(self):
    for form, original in zip(self.formset.initial_forms, self.formset.get_queryset()):
        yield InlineAdminForm(self.formset, form, self.fieldsets,
            self.opts.prepopulated_fields, original, self.readonly_fields,
            model_admin=self.model_admin)

and the only easily non-hackishly accessible hook we have there is overriding InlineAdminFormset.formset.get_queryset() which breaks other things.

Can I share some code nobody should ever really look at but works and makes me crack up laughing? I owe you one payne. Hope I can get to sleep tonight.

izi / django-admin-tools / issues / #113, Omit object name from Django's TabularInline admin view When displaying a TabularInline in Django, the value of each field is displayed. Omit object name from Django's TabularInline admin view Create issue. Issue #113 wontfix. Mridang Agarwalla created an issue 2012-10-16. When displaying a

@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)

Making queries | Django documentation, from blog.models import Author >>> joe = Author.objects.create(name="Joe") exclude(**kwargs): Returns a new QuerySet containing objects that do not match​  thepost = Content.objects.filter(name="test").first() Note that the two are not strictly the same. Manager method get will raise not only an exception in the case there's no record you're querying for but also when multiple records are found.

You could use css to hide the paragraph

Model Meta options | Django documentation, The attribute name of the manager, for example, 'objects' , to use for the or as part of migrations and remove them as part of a flush management command. I would like to change how these are named in the Admin. Ideally, I would like to be able to change it from "MyModelName object" to, as in the "Policy" object example, something like "Policy: {{ value of the policy's "Policy Name" field. }}. I was thinking that __unicode__ for my Patient model handled this, but it doesn't appear to. Any

I took a slightly different approach. It's a little hackish. This replaces the "original" string with a blank string, so the td for class=original still gets rendered leaving a gap above the edit boxes.

I like the CSS solution better (I had to use 'padding-top: 5px;' to get the rendering right).

models.py:
class Model(model.Model):
  general_questions = models.TextField()
  _hide = False

  def __unicode__(self):
    if _hide:
      return ''
admin.py:
class ModelInline(admin.TabularInline):
    model = Model
    extra = 0

class ModelAdmin(admin.ModelAdmin):
  inlines = [ModelInline, ]

  def render_change_form(self, request, context, *args, **kwargs):
    for formset in context['inline_admin_formsets']:
      qs = formset.formset.queryset
        for model_obj in qs:
          model_obj._hide = True

  return super(ModelAdmin, self).render_change_form(request, context, *args, **kwargs)

Conditional Expressions | Django documentation, from datetime import date, timedelta >>> from django.db.models import Case, CharField, Value, When >>> Client.objects.create( name='Jane Doe',  I'm using Django's TabularInline admin view to edit category objects related to a main topic object, as shown 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 case anyone is looking to hide the header on a StackedInline, I used Rick´s approach but adding this css:

div.inline-related h3{
   visibility: hidden;
   height: 0;
}

delattr() and del() in Python, The delattr() method is used to delete the named attribute from the object, with the prior permission of the object. Syntax: delattr(object, name) The function takes​  I use Django-Tastypie for my API. Here is an example of how my app currently works, if Steve wants to message Bill, a new "Message" object is created, where Steve is the sender. When a message object is created, it also creates a "Thread" object. In this thread, the participants are Steve & Bill. I currently have a ThreadPreview resource.

Filtering for Empty or Null Values in a Django QuerySet, Django features a great many methods and functions to simplify even the most which allows you to generate a QuerySet of objects that match a particular set of As the name implies, exclude() functions by excluding all the matches from the​  Logging is configured as part of the general Django setup () function. Therefore, you can be certain that loggers are always ready for use in your project code. The full documentation for dictConfig format is the best source of information about logging configuration dictionaries. However, to give you a taste of what is possible, here are

How to use Django Rest Framework to safely delete your data, objects.filter(name="Ian").delete() will bypass the custom delete method we added in SoftDeleteModel and permanently remove all of the  Django Advanced queries with Q objects. Example. Given the model: We can use Q objects to create AND , OR conditions in your lookup query. For example, say we want all objects that have flag=True OR model_num>15. The above translates to WHERE flag=True OR model_num > 15 similarly for an AND you would do.

Model instance reference, The optional exclude argument lets you provide a list of field names For example, DateField fields use a Python datetime object to store data. It currently looks like this — note that it already imports django.contrib.admin: from django.contrib import admin # Register your models here. Register the models by copying the following text into the bottom of the file. This code simply imports the models and then calls admin.site.register to register each of them.

Comments
  • Thank you! I suspected that editing the template would be the real answer.
  • change padding-top to 5px to be consistent with rows without has_original
  • this works well in Django 1.11, just use 10px for padding-top.
  • Unfortunately, this will hide the edit button when show_change_link is set to True (the link is within the paragraph and the text does not have its own wrapping element...)
  • I like this approach but it does work on my Django 2.1.7.