django-modelforms
This project came about because our reusable administration has to deal with
related models that have unique_together constraints (and modern UniqueConstraint)
that were not being properly validated by the default implementation.
It occurs because our forms don't show the related field, it's not something we want the user to be able to edit. This has the nasty side-effect of excluding the related field from validation checks, so uniqueness (with respect to the related field) is not tested.
The form therefore validates, and a database update is attempted - only to fail when integrity constraints are enforced by the backend.
Installation
pip install django-modelforms
Or with uv:
uv add django-modelforms
Usage
Simply use modelforms.forms.ModelForm instead of django.forms.ModelForm:
from modelforms.forms import ModelForm
class BookForm(ModelForm):
class Meta:
model = Book
fields = ['title', 'rrp']
This will properly validate both legacy unique_together constraints and modern
UniqueConstraint definitions in your model's Meta.constraints.
Supported Django and Python Versions
- Django 4.2, 5.2, 6.0
- Python 3.10, 3.11, 3.12, 3.13
Why?
Django bug #13091 was filed in March 2010 and still has not been fixed.
There has been discussion on the mailing lists and a number of patches proposed, but none have been accepted.
To stop encountering this in our projects we decided to write something generic that can easily be used without having to wait for an upstream fix.
Development
This project uses uv and tox for development:
# Install development dependencies
uv sync
# Run tests
uv run tox
# Run tests for a specific environment
uv run tox -e py312-django52
# Run linting
uv run tox -e lint
License
BSD-3-Clause
Metadata
Release files for django-modelforms 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_modelforms-1.0.1.tar.gz | 11.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_modelforms-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.5 kB
Release files / django_modelforms-1.0.1.tar.gz
| Download URL | django_modelforms-1.0.1.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f9ac32f41ff66ab3884d56f08fa12b2dae5cc2964ddd5a1f620a8cc35ed8c53
|
|
BLAKE2b-256 checksum How to use checksums |
0b8eaedd5b58eeef8d5ff78f30439dca05194278b426dfc1b9b19799b6427e92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 6, 2026.
Transparency logRelease files / django_modelforms-1.0.1-py3-none-any.whl
| Download URL | django_modelforms-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
20895c85a0d7ebc34009e43297825bde7031eb755dac12c1f244fd5587c5867f
|
|
BLAKE2b-256 checksum How to use checksums |
4218f8ba58ae2b33ed79bd12d96ca5ffa83820282a7e30549b92cff4016a2238
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 6, 2026.
Transparency log