Skip to main content

Link related objects in Django admin using decorators

Project description

Django Admin Anchors

PyPI License Tests

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

  1. Clone the repository and enter the cloned folder
  2. (optional) Create and activate a dedicated Python virtual environment
  3. Run pip install -e ".[dev]" to install the projects requirements
  4. (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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-admin-anchors-2.0.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_admin_anchors-2.0.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

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

Hashes for django-admin-anchors-2.0.0.tar.gz
Algorithm Hash digest
SHA256 8d696cd90db97e2b9540ce3d14a298575b3b873d9ddc8c1fd6b6dc60e47e8b40
MD5 3f694f18c27ab66089b94d7bb8beecf0
BLAKE2b-256 33f776d52ffed03f7d3ed9d6254722f2af198f78643838f01894fcb62281b98c

See more details on using hashes here.

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

Hashes for django_admin_anchors-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9502b93c534fd49177d557bbe079034969f52a2c982074cbeab0884edc868225
MD5 1f80277e003f3d9569ec2f9e78d12b43
BLAKE2b-256 f4a3f2015eb3e994151e15543c1d436807a4a81e605cb02f1b613f286a0f711e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page