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
# yourapp/admin.py
from django.contrib import admin
from admin_anchors.decorators import admin_anchor
from yourapp.models import Player
@admin.register(Player)
class PlayerAdmin(admin.ModelAdmin):
list_display = ["__str__", "profile_link", "teams_link"]
@admin_anchor(field_name="profile")
def profile_link(self, instance):
return "Profile"
@admin_anchor(field_name="teams")
def teams_link(self, instance):
return f"{instance.teams.count()} teams"
Take a look at the tests/project
directory to see a runnable example project.
Contributing
Setup
- Clone the repository and enter the cloned folder
- (optional) Create and activate a dedicated Python virtual environment
- Run
pip install -e ".[dev]"
to install the projects requirements - (optional) Run
pre-commit install
to install the pre-commit hook
Pre-commit hook
Our pre-commit hook formats and lints the code.
Formatting and linting
- Run
black admin_anchors tests
to format the code - Run
flake8 admin_anchors tests
to lint the code
Testing
- Run
py.test --cov admin_anchors tests
to run the tests in the current Python env - Run
tox
to run the tests in all supported Python and Django environments
Makefile
All commands listed above have shortcut make recipes.
Take a look at the Makefile
to learn more.
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-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5579b9616bb38a8582c91efbf6c4abba775eb90beee43239cb80109e03aa255a |
|
MD5 | c451c7874f38ab997c2accf1eed0a3dd |
|
BLAKE2b-256 | d806176318b853db108671671f3d63168ff90b0cb8ea39cb4f30abe993837e0f |
Close
Hashes for django_admin_anchors-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39c3a18f5e78a7c8029472e6c50aeb538b48cfc2e939797829d0b9298269c9dd |
|
MD5 | d2e778886631787b4346cc01eb429666 |
|
BLAKE2b-256 | 6901e41431b934c19d2b4d634ac01c5efebb7b7ad5cd1973d31ed761a8ee7d06 |