The Django admin allows to list rows in an easy way. Some feature that seems to be "missing" is to jump in an efficient way to the detail view of a related object. For example if a model A
has a ForeignKey
to B
, then the ModelAdmin
of A
can show the __str__
of B
, but without a link.
This package provides a mixin to effectively add such links.
You can install the package with:
pip install django-adminlink
Once the package is installed, you can use the LinkFieldAdminMixin
mixin in the admins where you want ForeignKey
s and OneToOneField
s to be linked to the corresponding admin detail view of that object:
from django.contrib import admin
from django_adminlink.admin import LinkFieldAdminMixin
@admin.register(Movie)
class MovieAdmin(LinkFieldAdminMixin, admin.ModelAdmin):
list_display = ['__str__', 'genre']
If genre
is a ForeignKey
to a Genre
model for example, and Genre
has its own ModelAdmin
, it will automatically convert genre
into a column that adds a link to the admin detail view of the corresponding genre.