django-readonly-field


Namedjango-readonly-field JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/botify-labs/django-readonly-field
SummaryMake Django model fields readonly
upload_time2023-10-13 11:23:15
maintainerSofien Ben Ayed
docs_urlNone
authorJoachim Jablon
requires_python>=3.7,<4.0
licenseMIT
keywords django posgresql read-only
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =============================
Django Readonly Field
=============================

.. image:: https://img.shields.io/pypi/v/django-readonly-field?logo=pypi&logoColor=white
    :target: https://pypi.org/pypi/django-readonly-field
    :alt: Deployed to PyPI

.. image:: https://img.shields.io/pypi/pyversions/django-readonly-field?logo=pypi&logoColor=white
    :target: https://pypi.org/pypi/django-readonly-field
    :alt: Python library

.. image:: https://img.shields.io/github/stars/botify-labs/django-readonly-field?logo=github
    :target: https://github.com/botify-labs/django-readonly-field/
    :alt: GitHub Repository

.. image:: https://img.shields.io/github/actions/workflow/status/botify-labs/django-readonly-field/ci.yml?logo=github&branch=main
    :target: https://github.com/botify-labs/django-readonly-field/actions?workflow=CI
    :alt: Continuous Integration

.. image:: https://img.shields.io/readthedocs/django-readonly-field/stable?logo=read-the-docs&logoColor=white
    :target: https://django-readonly-field.readthedocs.io/
    :alt: Documentation

.. image:: https://raw.githubusercontent.com/botify-labs/django-readonly-field/python-coverage-comment-action-data/badge.svg
    :target: https://github.com/botify-labs/django-readonly-field/tree/python-coverage-comment-action-data
    :alt: Coverage

.. image:: https://img.shields.io/github/license/botify-labs/django-readonly-field?logo=open-source-initiative&logoColor=white
    :target: https://github.com/botify-labs/django-readonly-field/blob/master/LICENSE
    :alt: MIT License

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 2.2 to 4.2
+ With Python, tested from 3.7 to 3.11

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`` :

.. code-block:: python

    INSTALLED_APPS = [
        # ...
        "django_readonly_field",
    ]

In the model where you want some fields to be read-only:

.. code-block:: python

    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 <https://github.com/peopledoc/django-readonly-field>`_.

Tools used in rendering this package:

*  Cookiecutter_
*  `cookiecutter-djangopackage`_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/botify-labs/django-readonly-field",
    "name": "django-readonly-field",
    "maintainer": "Sofien Ben Ayed",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "sofien@botify.com",
    "keywords": "django,posgresql,read-only",
    "author": "Joachim Jablon",
    "author_email": "ewjoachim@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7e/71/82e641939562a871ee4b6fd0d265ce65a19b8f87e5c09fb35ebec2788e62/django_readonly_field-1.2.0.tar.gz",
    "platform": null,
    "description": "=============================\nDjango Readonly Field\n=============================\n\n.. image:: https://img.shields.io/pypi/v/django-readonly-field?logo=pypi&logoColor=white\n    :target: https://pypi.org/pypi/django-readonly-field\n    :alt: Deployed to PyPI\n\n.. image:: https://img.shields.io/pypi/pyversions/django-readonly-field?logo=pypi&logoColor=white\n    :target: https://pypi.org/pypi/django-readonly-field\n    :alt: Python library\n\n.. image:: https://img.shields.io/github/stars/botify-labs/django-readonly-field?logo=github\n    :target: https://github.com/botify-labs/django-readonly-field/\n    :alt: GitHub Repository\n\n.. image:: https://img.shields.io/github/actions/workflow/status/botify-labs/django-readonly-field/ci.yml?logo=github&branch=main\n    :target: https://github.com/botify-labs/django-readonly-field/actions?workflow=CI\n    :alt: Continuous Integration\n\n.. image:: https://img.shields.io/readthedocs/django-readonly-field/stable?logo=read-the-docs&logoColor=white\n    :target: https://django-readonly-field.readthedocs.io/\n    :alt: Documentation\n\n.. image:: https://raw.githubusercontent.com/botify-labs/django-readonly-field/python-coverage-comment-action-data/badge.svg\n    :target: https://github.com/botify-labs/django-readonly-field/tree/python-coverage-comment-action-data\n    :alt: Coverage\n\n.. image:: https://img.shields.io/github/license/botify-labs/django-readonly-field?logo=open-source-initiative&logoColor=white\n    :target: https://github.com/botify-labs/django-readonly-field/blob/master/LICENSE\n    :alt: MIT License\n\nMake some Django model fields readonly. In other words, it lets you tell Django to\nread some fields from your database, but never try to write those back. It can be\nuseful if your fields are populated by triggers or something.\n\nRequirements\n------------\n\n+ **Postgresql only**\n+ Django, tested from 2.2 to 4.2\n+ With Python, tested from 3.7 to 3.11\n\nDocumentation\n-------------\n\nThe full documentation is at https://django-readonly-field.readthedocs.org.\n\nQuickstart\n----------\n\nInstall Django Readonly Field::\n\n    pip install django-readonly-field\n\nIn your ``settings.py`` :\n\n.. code-block:: python\n\n    INSTALLED_APPS = [\n        # ...\n        \"django_readonly_field\",\n    ]\n\nIn the model where you want some fields to be read-only:\n\n.. code-block:: python\n\n    class Spaceship(models.Model):\n        name = models.CharField(max_length=100)\n        color = models.CharField(max_length=16)\n\n        class ReadonlyMeta:\n            readonly = [\"color\"]\n\nThat's it. Now, Django won't try to write the ``color`` field on the database.\n\n\nWarning\n-------\n\nDjango won't try to write those fields. Consequence is that your Database\n**must** be ok with Django not writing those fields. They should either\nbe nullable or have a database default or be filled by a trigger, otherwise\nyou will get an ``IntegrityError``.\n\nDon't forget that Django model field defaults won't become database defaults.\nYou might have to write an SQL migration for this.\n\n\nRunning Tests\n--------------\n\nYou will need a usable Postgresql database in order to test the project.\n\n::\n\n    source <YOURVIRTUALENV>/bin/activate\n    export DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/NAME\n    (myenv) $ pip install -r requirements.txt\n\nRun tests for a specific version\n\n::\n\n    (myenv) $ pytest\n\n\nRun tests for all versions (if tox is installed globally, you don't need a\nvirtual environment)\n\n::\n\n    $ tox\n\n\nCredits\n---------\n\nThis repository was once available at `peopledoc/django-readonly-field <https://github.com/peopledoc/django-readonly-field>`_.\n\nTools used in rendering this package:\n\n*  Cookiecutter_\n*  `cookiecutter-djangopackage`_\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Make Django model fields readonly",
    "version": "1.2.0",
    "project_urls": {
        "Documentation": "https://django-readonly-field.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/botify-labs/django-readonly-field",
        "Repository": "https://github.com/botify-labs/django-readonly-field"
    },
    "split_keywords": [
        "django",
        "posgresql",
        "read-only"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "43297dc40d40a3ad509d54b290e86d239646aaae4fa1d6643f35045663bed936",
                "md5": "051e72e9ced8a9ec4b393db7b8a9dba8",
                "sha256": "d4ad3047b58e2be1032102fc1dce0058c03a96cb6d8042a624ce7a588597098f"
            },
            "downloads": -1,
            "filename": "django_readonly_field-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "051e72e9ced8a9ec4b393db7b8a9dba8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 5268,
            "upload_time": "2023-10-13T11:23:14",
            "upload_time_iso_8601": "2023-10-13T11:23:14.186940Z",
            "url": "https://files.pythonhosted.org/packages/43/29/7dc40d40a3ad509d54b290e86d239646aaae4fa1d6643f35045663bed936/django_readonly_field-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7e7182e641939562a871ee4b6fd0d265ce65a19b8f87e5c09fb35ebec2788e62",
                "md5": "996284ae488833028c5d82fee64c3fa3",
                "sha256": "8751c8eb66fb2cc6d1def8a2790eb9f37b7533a00f1d4bb25fdd268bae9e2330"
            },
            "downloads": -1,
            "filename": "django_readonly_field-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "996284ae488833028c5d82fee64c3fa3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 4737,
            "upload_time": "2023-10-13T11:23:15",
            "upload_time_iso_8601": "2023-10-13T11:23:15.811955Z",
            "url": "https://files.pythonhosted.org/packages/7e/71/82e641939562a871ee4b6fd0d265ce65a19b8f87e5c09fb35ebec2788e62/django_readonly_field-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-13 11:23:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "botify-labs",
    "github_project": "django-readonly-field",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-readonly-field"
}
        
Elapsed time: 0.12986s