Skip to main content

Make Django model fields readonly

Project description

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.11+ (until proven otherwise)

  • Running under Python 2.7 or 3.5+

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.5 (2019-04-23)

  • Run tests for Django 2.2 and Python 3.5, 3.6 and 3.7

1.0.4 (2018-12-17)

  • Drop support of Python 3.4

  • Confirm support of Python 3.7

  • Drop support of Django 1.8

  • Drop support of Django 1.9

  • Drop support of Django 1.10

  • Confirm support of Django 2.0

  • Confirm support of Django 2.1

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-readonly-field-1.0.5.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_readonly_field-1.0.5-py2.py3-none-any.whl (6.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-readonly-field-1.0.5.tar.gz.

File metadata

  • Download URL: django-readonly-field-1.0.5.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for django-readonly-field-1.0.5.tar.gz
Algorithm Hash digest
SHA256 eeaca19a20abc48c0a3b323b9f909b9cc6b9bf803ef3a2b4f382c302400c840d
MD5 787dee8b08dee22a8cccbe9a6e8f375e
BLAKE2b-256 2829ccc82beb29e3fd911232cba0aab520f6a5b71b3f92fb6ca4ee0e0a8f273b

See more details on using hashes here.

File details

Details for the file django_readonly_field-1.0.5-py2.py3-none-any.whl.

File metadata

  • Download URL: django_readonly_field-1.0.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for django_readonly_field-1.0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d8b7eb152a01c37ec0515b0f1de5657ce9cce733045a74fd661ca55528126e38
MD5 64590f36040aeaac95975c94478eed29
BLAKE2b-256 feb10a18c9545dc0d9538d27e08e70e02df2f77d37afd8536d6dde71b9c90e88

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page