Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Make Django model fields readonly

Project Description

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.


  • Postgresql only
  • Django, obviously. v1.8+ (until proven otherwise)
  • Running under Python 2.7 or 3.4+


The full documentation is at


Install Django Readonly Field:

pip install django-readonly-field

In your :

    # ...

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.


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
(myenv) $ pip install -r requirements_test.txt

Run tests for a specific version

(myenv) $ python

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


Tools used in rendering this package:


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 History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django_readonly_field-1.0.2-py2.py3-none-any.whl (7.1 kB) Copy SHA256 Checksum SHA256 3.5 Wheel Sep 22, 2017
django-readonly-field-1.0.2.tar.gz (6.9 kB) Copy SHA256 Checksum SHA256 Source Sep 22, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting