Link related objects in Django admin using decorators
Project description
Django Admin Anchors
Turn Django admin list display items into clickable links to related objects using decorators.
Clicking admin anchors will redirect to a filtered changelist view showing the related objects. This allows you to get a quick overview and run actions on the filtered objects.
Installation
pip install django-admin-anchors
Usage
Take a look at the tests/project directory to see a runnable example project.
Add links to the object list page
from django.contrib import admin
from admin_anchors import admin_anchor
from yourapp.models import Team
@admin.register(Team)
class TeamAdmin(admin.ModelAdmin):
list_display = ["__str__", "captain_link", "captains_profile_link", "members_link"]
@admin_anchor("captain")
def captain_link(self, instance):
return str(instance.captain)
@admin_anchor("captain.profile")
def captains_profile_link(self, instance):
return "Captains profile"
@admin_anchor("members")
def members_link(self, instance):
return f"{instance.members.count()} members"
Add links to the object update page
from django.contrib import admin
from admin_anchors import admin_anchor
from yourapp.models import Player
@admin.register(Player)
class PlayerAdmin(admin.ModelAdmin):
readonly_fields = ["profile_link"]
@admin_anchor("profile")
def profile_link(self, instance):
return "Profile"
Example project
Take a look at our Django example project under tests/project.
You can run it by executing these commands:
uv syncuv run tests/project/manage.py migrateuv run tests/project/manage.py createsuperuseruv run tests/project/manage.py runserver
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_admin_anchors-4.4.0.tar.gz.
File metadata
- Download URL: django_admin_anchors-4.4.0.tar.gz
- Upload date:
- Size: 167.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2692945c7475a8ee5d3b530513d4e9ecdc8870ba7e3f8c4e862c7e604fb70296
|
|
| MD5 |
ac53d15251811bc27abf8c94a90bd12f
|
|
| BLAKE2b-256 |
f14b33142e2c2dccbf40f9a5d334d4698453550f1c75599c14631eeff1a76198
|
File details
Details for the file django_admin_anchors-4.4.0-py3-none-any.whl.
File metadata
- Download URL: django_admin_anchors-4.4.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc8f6dd35fd54121efaad3d26e93f6a60bf13b490b9e75d7ee667ab63530fdf0
|
|
| MD5 |
6b17d52d1b833ca939f9b74fa1fec6f8
|
|
| BLAKE2b-256 |
5a1063c3a1fee509501c64beba27e7e9183d9f6a339ad18b44b839ddc8e790e3
|