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 installto install the pre-commit hook
Pre-commit hook
Our pre-commit hook formats and lints the code.
Formatting and linting
- Run
black admin_anchors teststo format the code - Run
flake8 admin_anchors teststo lint the code
Testing
- Run
py.test --cov admin_anchors teststo run the tests in the current Python env - Run
toxto 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
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-2.0.0.tar.gz.
File metadata
- Download URL: django-admin-anchors-2.0.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d696cd90db97e2b9540ce3d14a298575b3b873d9ddc8c1fd6b6dc60e47e8b40
|
|
| MD5 |
3f694f18c27ab66089b94d7bb8beecf0
|
|
| BLAKE2b-256 |
33f776d52ffed03f7d3ed9d6254722f2af198f78643838f01894fcb62281b98c
|
File details
Details for the file django_admin_anchors-2.0.0-py3-none-any.whl.
File metadata
- Download URL: django_admin_anchors-2.0.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9502b93c534fd49177d557bbe079034969f52a2c982074cbeab0884edc868225
|
|
| MD5 |
1f80277e003f3d9569ec2f9e78d12b43
|
|
| BLAKE2b-256 |
f4a3f2015eb3e994151e15543c1d436807a4a81e605cb02f1b613f286a0f711e
|