Django Admin: how to link to another model from one model list view ?

1,330 views
Skip to first unread message

Olivier

unread,
Jun 25, 2020, 4:07:15 AM6/25/20
to Django users
Hello,

Let say your app deals with Book and Author models.

Within Django Admin, you can display a list of currently stored Books.
I
How can you implement the following:
1. For each Book entry within Book Listing page (like http://foobar.com/admin/myapp/book/), book's title and authors arr both displayed,
2. When clicking over book's title, you go to book edit page (like http://foobar.com/admin/myapp/book/7/change)
3. When clicking over any of book's authors,  you go to corresponding author edit page (like http://foobar.com/admin/myapp/author/25/change)

I did tried with list_display_links but it linked to Book edit page, not Author edit page.

I also tried with building custom URLs like <a href="/admin/myapp/author/25/change">Author Name</a>, but it exactly this URL value
instead of showing a link.
(looking at page source code, it seems my browser received an escaped value like "&lt;a&gt; href= ..." instead of expected "<a> href= ...").

Any hint ?

Best regards

Olivier

unread,
Jun 29, 2020, 2:46:12 AM6/29/20
to Django users
I've found [1] which seems to match what I was after

I hope this could also help others ...
Reply all
Reply to author
Forward
0 new messages