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
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"
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-2.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d696cd90db97e2b9540ce3d14a298575b3b873d9ddc8c1fd6b6dc60e47e8b40 |
|
MD5 | 3f694f18c27ab66089b94d7bb8beecf0 |
|
BLAKE2b-256 | 33f776d52ffed03f7d3ed9d6254722f2af198f78643838f01894fcb62281b98c |
Close
Hashes for django_admin_anchors-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9502b93c534fd49177d557bbe079034969f52a2c982074cbeab0884edc868225 |
|
MD5 | 1f80277e003f3d9569ec2f9e78d12b43 |
|
BLAKE2b-256 | f4a3f2015eb3e994151e15543c1d436807a4a81e605cb02f1b613f286a0f711e |