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.
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 edit 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"
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
Close
Hashes for django_admin_anchors-2.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5720b685ace5391b9dd27f3e9dbb548e996ce5390d903b6b81fa8d9225d1b2cc |
|
MD5 | fce11c5b96c15b4d0bac24058a61b17e |
|
BLAKE2b-256 | eb543e3b5c600bd45b7e85db4ce477d64badff06d01cf596e1a6ccc88615f65e |
Close
Hashes for django_admin_anchors-2.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9659769b8b85cb02352f3bbcbc76b7c120581533216961ee41c793db30b9e402 |
|
MD5 | 4d15df89076a91678671e7bb87291762 |
|
BLAKE2b-256 | 7800fcff13e67db886546b4cb85b0877d6d68166b43f773d47abcc3d6e14692d |