Django Readonly Field
Make some Django model fields readonly. In other words, it lets you tell Django to read some fields from your database, but never try to write those back. It can be useful if your fields are populated by triggers or something.
Requirements
Postgresql only
Django, tested from 4.2 to 5.1
With Python, tested from 3.8 to 3.12
Documentation
The full documentation is at https://django-readonly-field.readthedocs.org.
Quickstart
Install Django Readonly Field:
pip install django-readonly-field
In your settings.py :
INSTALLED_APPS = [
# ...
"django_readonly_field",
]
In the model where you want some fields to be read-only:
class Spaceship(models.Model):
name = models.CharField(max_length=100)
color = models.CharField(max_length=16)
class ReadonlyMeta:
readonly = ["color"]
That’s it. Now, Django won’t try to write the color field on the database.
Warning
Django won’t try to write those fields. Consequence is that your Database must be ok with Django not writing those fields. They should either be nullable or have a database default or be filled by a trigger, otherwise you will get an IntegrityError.
Don’t forget that Django model field defaults won’t become database defaults. You might have to write an SQL migration for this.
Running Tests
You will need a usable Postgresql database in order to test the project.
source <YOURVIRTUALENV>/bin/activate export DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/NAME (myenv) $ pip install -r requirements.txt
Run tests for a specific version
(myenv) $ pytest
Run tests for all versions (if tox is installed globally, you don’t need a virtual environment)
$ tox
Credits
This repository was once available at peopledoc/django-readonly-field.
Tools used in rendering this package:
Metadata
Release files for django-readonly-field 1.3.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 | Actions |
|---|---|---|---|---|
| django_readonly_field-1.3.0.tar.gz | 4.9 kB | Without provenance | Details for django_readonly_field-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_readonly_field-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for django_readonly_field-1.3.0-py3-none-any.whl |
Total release size: 10.6 kB
Release files / django_readonly_field-1.3.0.tar.gz
| Download URL | django_readonly_field-1.3.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f5ce043fa0e638a292dccceeec34be7fed103e455263544971332d14b3c3b31b
|
|
BLAKE2b-256 checksum How to use checksums |
bd0ca4f8cac2868e06c83ceb4e00e8e50df395596e794ac54678111eafa00d57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure
|
Release files / django_readonly_field-1.3.0-py3-none-any.whl
| Download URL | django_readonly_field-1.3.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f83cc468937179d62a4162e39813dc453b34bea7028d12b68d01cf739f368df
|
|
BLAKE2b-256 checksum How to use checksums |
aaa9e0cec0fff38fe2be06d41a1cff70ea561deb83ec2af73b708522f071a32e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure
|
Security for django-readonly-field 1.3.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.