Sunday, June 28, 2020

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

I've found [1] which seems to match what I was after
[1] https://avilpage.com/2017/11/django-tips-tricks-hyperlink-foreignkey-admin.html

I hope this could also help others ...

Le jeudi 25 juin 2020 10:07:15 UTC+2, Olivier a écrit :
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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/eb924d2c-ef67-4b81-a118-a1b1ecce6cceo%40googlegroups.com.

No comments:

Post a Comment