Skip to main content
https://badge.fury.io/py/django-readonly-field.png https://travis-ci.org/peopledoc/django-readonly-field.png?branch=master https://img.shields.io/codecov/c/github/peopledoc/django-readonly-field/master.svg

Make Django model fields readonly. In other words, make it so that Django will read from your fields in your database, but never try to write them. It can be useful if your fields are populated by triggers or something.

Requirements

  • Postgresql only

  • Django, obviously. v1.8+ (until proven otherwise)

  • Running under Python 2.7 or 3.4+

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 an usable Postgresql database in ordre to test the project.

source <YOURVIRTUALENV>/bin/activate
export DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/NAME
(myenv) $ pip install -r requirements_test.txt

Run tests for a specific version

(myenv) $ python runtests.py

Run tests for all versions (if tox is installed globally, you don’t need a virtual environment)

$ tox

Using the project

Many operations are documented in the Makefile. For more information, use:

$ make help

Credits

Tools used in rendering this package:

History

1.0.3 (2018-04-26)

  • Python 3.6 support

  • Multiple databases support

  • Github organization changed to “peopledoc”

1.0.2 (2017-09-22)

  • Added tests for Django 1.11

1.0.1 (2016-10-19)

  • Added support for Python 3.4 and current Django stable

  • Fix a thread bug that would make the package usable only for test and not for real :/

1.0.0 (2016-09-15)

  • First stable version

0.2.0 (2016-09-14)

  • Rationalized the writing of readonly (vs read-only)

  • Defined default app config

0.1.1 (2016-09-13)

  • CI improvements

  • Code linting

0.1.0 (2016-09-02)

  • First release on PyPI.

Release files for django-readonly-field 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-readonly-field 1.0.3
File Size Uploaded
django-readonly-field-1.0.3.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-readonly-field 1.0.3
File Interpreter ABI Platform
django_readonly_field-1.0.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 14.2 kB

Release files / django-readonly-field-1.0.3.tar.gz

Download URL django-readonly-field-1.0.3.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f2afc8e02996aa9e169846bb79fa07df833d5fc2c63149bf29e531bef905fe10
BLAKE2b-256 checksum
How to use checksums
67e7c1e3953f6963280357e68af202a8b8f498462372704daa306feb6ab65efe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_readonly_field-1.0.3-py2.py3-none-any.whl

Download URL django_readonly_field-1.0.3-py2.py3-none-any.whl
Size 7.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
568806a123f966257987f1c17037288c3e8eb648f293cef306a49235822aa2a9
BLAKE2b-256 checksum
How to use checksums
bf23902e59bfc5552d8151eb739ed4fafbdba61bb7f7436750a35d675c797695
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.3.0

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.0.5

2 release files

1.0.4

2 release files

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page