Mridang Agarwalla
Mridang Agarwalla

Reputation: 44958

Customisations to the TabularInline in Django

I have two models e.g. Book and Author. An author can have many books and therefore I have a foreign-key from the Book to the Author table.

I display the the Book and the Author record in my Django application using the TabularInline class. This works fine but I get the a Book object on the top-left corner of every book row displayed in the author's inline admin. How can I remove this? I'm trying to avoid editing the Django admin templates if possible and some have suggested that I should override the __unicode__ method on the Book model but I would like to hide it entirely.

Is this possible?

My Book model also references another model called Publisher. The publisher's __unicode__ value is displayed in one of the columns of book records in the TabularInline but I'd like to be able to link this to the admin page for that Publisher record instead of just displaying simple text.

What should I specify to do this?

Upvotes: 3

Views: 1662

Answers (2)

ilvar
ilvar

Reputation: 5841

You cah hide "Book object" links with some JS added to the AdminSite. It should be something like:

django.jQuery('.dynamic-phone_set h3').hide();

Upvotes: 1

jpic
jpic

Reputation: 33410

Why not just override the admin template to add some CSS ?

For example, in templates/admin/testapp/author/change_form.html:

{% extends 'admin/change_form.html' %}

{% block content %}
    <style type="text/css">
    fieldset.module td.original p { display:none; }
    </style>
    {{ block.super }}
{% endblock %}

You may do that globally, per app or per model.

It works and seems pretty safe, unlike overriding the fieldset template itself - which makes sense to avoid doing.

Upvotes: 6

Related Questions