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.2
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 | Actions |
|---|---|---|---|---|
| django_modelforms-1.0.2.tar.gz | 12.4 kB | With provenance | Details for django_modelforms-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_modelforms-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for django_modelforms-1.0.2-py3-none-any.whl |
Total release size: 18.4 kB
Release files / django_modelforms-1.0.2.tar.gz
| Download URL | django_modelforms-1.0.2.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
58cf315b208ddabcdbe26b7379f992420603236159e7290fbd6108026a587749
|
|
BLAKE2b-256 checksum How to use checksums |
fe7cf903bb9d3a0d2080b7f22df237e29268512a0a3aa637552806a803712b68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 27, 2026.
Transparency logRelease files / django_modelforms-1.0.2-py3-none-any.whl
| Download URL | django_modelforms-1.0.2-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0737733f61d16831a4b64fdf6a5f9e0a38f50decdedfbf1061deecd971eb5a9b
|
|
BLAKE2b-256 checksum How to use checksums |
df9b112f0e9afb9e0992f5510f4e4f392ab14a313069812ef0666020c01a7a7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 27, 2026.
Transparency logSecurity for django-modelforms 1.0.2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for django_modelforms-1.0.2.tar.gz
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 Oct 27, 2026.
Transparency logA 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.