{"id":22927202,"url":"https://github.com/hapytex/django-admin-backref","last_synced_at":"2026-04-28T08:32:45.115Z","repository":{"id":232996899,"uuid":"785209955","full_name":"hapytex/django-admin-backref","owner":"hapytex","description":"Generate admin URLs through the models.","archived":false,"fork":false,"pushed_at":"2024-04-13T19:24:52.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-07T10:14:27.422Z","etag":null,"topics":["django","django-admin","urls"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hapytex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-04-11T12:28:02.000Z","updated_at":"2024-04-12T14:10:41.000Z","dependencies_parsed_at":"2024-04-19T01:46:09.034Z","dependency_job_id":null,"html_url":"https://github.com/hapytex/django-admin-backref","commit_stats":null,"previous_names":["hapytex/django-admin-backref"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapytex%2Fdjango-admin-backref","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapytex%2Fdjango-admin-backref/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapytex%2Fdjango-admin-backref/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapytex%2Fdjango-admin-backref/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hapytex","download_url":"https://codeload.github.com/hapytex/django-admin-backref/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246665982,"owners_count":20814412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-admin","urls"],"created_at":"2024-12-14T09:13:54.459Z","updated_at":"2026-04-28T08:32:45.045Z","avatar_url":"https://github.com/hapytex.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# django-admin-backref\n\n[![PyPi version](https://badgen.net/pypi/v/django-admin-backref/)](https://pypi.python.org/pypi/django-admin-backref/)\n[![Documentation Status](https://readthedocs.org/projects/django-admin-backref/badge/?version=latest)](http://django-admin-backref.readthedocs.io/?badge=latest)\n[![PyPi license](https://badgen.net/pypi/license/django-admin-backref/)](https://pypi.python.org/pypi/django-admin-backref/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\nGenerate admin URLs through the models.\n\nThis package automatically attaches an `.admin_links` object to all models with a registered `ModelAdmin` (for the default admin site).\n\nThis can then be used to generate the links both from the perspective of the *model object* as well as the model. One can then generate the path, or a link to that path with:\n\n```python3\nUser.admin_links  # '/admin/auth/user/'\nUser.admin_links.add  # '/admin/auth/user/add'\nUser.admin_links.label  # '\u003ca href=\"/admin/auth/user/\"\u003e\u0026lt;class \u0026#x27;django.contrib.auth.models.User\u0026#x27;\u0026gt;\u003c/a\u003e'\nUser(pk=1, username='username').admin_links  # '/admin/auth/user/1/change/'\nUser(pk=1, username='username').admin_links.delete  # '/admin/auth/user/1/delete/'\nUser(pk=1, username='username').admin_links.label  # '\u003ca href=\"/admin/auth/user/1/change/\"\u003eusername\u003c/a\u003e'\nUser(pk=1, username='username').admin_links.add  # '/admin/auth/user/add/'\n```\n\n## Installation\n\nYou install the package with:\n\n```bash\npip install django-admin-backref\n```\n\nNext you can add the `django_admin_backref` to the `INSTALLED_APPS`:\n\n```python3\n# settings.py\n\nINSTALLED_APPS = [\n    # …,\n    'django.contrib.admin',\n    # …,\n    'django_admin_backref',\n    # …\n]\n```\n\nNext all the models that have been registered for the *default* admin site, will automatically have a `.admin_links` attribute to access the admin URLs. If a model has already such attribute, for example because some other package, it will *not* override this.\n\n## Usage\n\nThe `.admin_links` will generate an `AdminLink` object. For each view name, it then has attributes. We can access these in four ways:\n\n - \u003ccode\u003e.\u003ci\u003ename\u003c/i\u003e\u003c/code\u003e: the URL for the admin link with that name;\n - \u003ccode\u003e.\u003ci\u003ename\u003c/i\u003e_label\u003c/code\u003e: a *safe* string that contains an `\u003ca href=\"\"\u003e` to that admin URL, and uses the label of the object;\n - \u003ccode\u003e.get_\u003ci\u003ename\u003c/i\u003e()\u003c/code\u003e: the URL for the admin link with that name as a method; and\n - \u003ccode\u003e.get_\u003ci\u003ename\u003c/i\u003e_label()\u003c/code\u003e: a *safe* string that contains an `\u003ca href=\"\"\u003e` to that admin URL, and uses the label of the object as a method.\n\nFor a simple model and for a simple admin, so without additional packages, for the class we have `.add`, `.changelist`, for *instances* it also contains `.change`, `.delete` and `.history`. Additional packages like `django-import-export` or special `ModelAdmin`s like the one for the `User` model introduce additional paths, like for example `.import` and `.password_change`.\n\nThe label is determined by first calling `.get_label()` on the model object, if that does not work it takes the `str(…)` of the instance or model class. Finally if these raise an error, it will take the empty string.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapytex%2Fdjango-admin-backref","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhapytex%2Fdjango-admin-backref","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapytex%2Fdjango-admin-backref/lists"}