django-admin-reversefields
Manage reverse ForeignKey / OneToOne relationships from the parent change form in Django admin.
django-admin-reversefields adds parent-side selector fields (single or multi-select) that stay in sync with the child rows on save — without hand-rolling custom forms, querysets, or save logic.
Quickstart · Recipes · Caveats
Why
Django admin gives you inlines for reverse relations. They’re great for creating or editing related rows, but they don’t give you a simple selector to attach existing child objects to a parent from the parent form.
When you implement this yourself, you usually repeat the same plumbing:
- form field + widget wiring
- queryset filtering
- initial value population
- unbind / bind save logic
- transaction handling
This package turns that pattern into a reusable mixin + config.
What it does
You have a parent model (Organization / Company / Tenant) and a child model (Site / Department / Project) where the child has a ForeignKey to the parent.
This package adds virtual fields to the parent admin form so you can select which existing child rows belong to the parent. On save, it synchronizes the child rows’ foreign keys to match the selection.
Supports:
- single-select or multi-select
- choice filtering (example: “unassigned or already assigned to this parent”)
- transactional synchronization on save
Install
pip install django-admin-reversefields
Supported versions:
- Django: 4.2, 5.0, 5.1, 5.2
- Python: 3.10–3.13
Quickstart
Example: assign Site rows to an Organization from the Organization admin page.
from django.contrib import admin
from django_admin_reversefields.mixins import ReverseRelationAdminMixin, ReverseRelationConfig
@admin.register(Organization)
class OrganizationAdmin(ReverseRelationAdminMixin, admin.ModelAdmin):
reverse_relations = {
"sites": ReverseRelationConfig(
model=Site,
fk_field="organization",
multiple=True,
limit_choices_to=unbound_or_current, # optional
),
}
fieldsets = (
("Details", {"fields": ("name",)}),
("Sites", {"fields": ("sites",)}),
)
Include each virtual field name in fieldsets (or fields). When you save the parent, the mixin updates the child rows’ foreign keys to match the current selection.
Development
This project uses uv for local tooling.
Setup:
uv sync
Common commands:
uv run ruff check .
uv run django-admin test
uv run sphinx-build -b html docs docs/_build/html -W
Run the demo/test app:
export DJANGO_DB_NAME=db.sqlite3
uv run python manage.py migrate
uv run python manage.py seed
uv run python manage.py runserver
Log in at /admin/ with admin / admin and edit a company to see the reverse fields.
Release
uv build
twine upload dist/*
License
See LICENSE
Metadata
Release files for django-admin-reversefields 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_admin_reversefields-0.2.0.tar.gz | 15.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_admin_reversefields-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.7 kB
Release files / django_admin_reversefields-0.2.0.tar.gz
| Download URL | django_admin_reversefields-0.2.0.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a5fc635fd1e0099fe48215670556b05944bd0305ed2c7a96e162c7aae5fe0b7
|
|
BLAKE2b-256 checksum How to use checksums |
e68a25c04682093a1d465dbd212493a8468be4f8086b1bdef5d49ca3fc3e6dfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / django_admin_reversefields-0.2.0-py3-none-any.whl
| Download URL | django_admin_reversefields-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d2905b52ea2e5cc1c61829920985667fddc4f2ade2da9f16d5df62fa331fd95
|
|
BLAKE2b-256 checksum How to use checksums |
03f53134793b33bccb4ea25d6e4d620cfd3dd1038a59fb10ac8a0c0308a3cb5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for django-admin-reversefields 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.