django-readonly-field


Namedjango-readonly-field JSON
Version 1.3.0 PyPI version JSON
download
home_pagehttps://github.com/botify-labs/django-readonly-field
SummaryMake Django model fields readonly
upload_time2024-08-09 15:49:47
maintainerSofien Ben Ayed
docs_urlNone
authorJoachim Jablon
requires_python<4.0,>=3.8
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
=============================

|pypi| |version| |github| |ci| |doc| |cov| |license|

.. |pypi| 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

.. |version| 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

.. |github| 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

.. |ci| 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

.. |doc| 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

.. |cov| 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

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

.. 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": "<4.0,>=3.8",
    "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/bd/0c/a4f8cac2868e06c83ceb4e00e8e50df395596e794ac54678111eafa00d57/django_readonly_field-1.3.0.tar.gz",
    "platform": null,
    "description": "=============================\nDjango Readonly Field\n=============================\n\n|pypi| |version| |github| |ci| |doc| |cov| |license|\n\n.. |pypi| 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.. |version| 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.. |github| 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.. |ci| 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.. |doc| 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.. |cov| 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.. |license| 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 4.2 to 5.1\n+ With Python, tested from 3.8 to 3.12\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.3.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": "aaa9e0cec0fff38fe2be06d41a1cff70ea561deb83ec2af73b708522f071a32e",
                "md5": "7d802bfde245486ffe698e61786b298e",
                "sha256": "4f83cc468937179d62a4162e39813dc453b34bea7028d12b68d01cf739f368df"
            },
            "downloads": -1,
            "filename": "django_readonly_field-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7d802bfde245486ffe698e61786b298e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 5655,
            "upload_time": "2024-08-09T15:49:45",
            "upload_time_iso_8601": "2024-08-09T15:49:45.803571Z",
            "url": "https://files.pythonhosted.org/packages/aa/a9/e0cec0fff38fe2be06d41a1cff70ea561deb83ec2af73b708522f071a32e/django_readonly_field-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd0ca4f8cac2868e06c83ceb4e00e8e50df395596e794ac54678111eafa00d57",
                "md5": "4ba4a8a7519ef7005393524aa89d8dec",
                "sha256": "f5ce043fa0e638a292dccceeec34be7fed103e455263544971332d14b3c3b31b"
            },
            "downloads": -1,
            "filename": "django_readonly_field-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4ba4a8a7519ef7005393524aa89d8dec",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 4898,
            "upload_time": "2024-08-09T15:49:47",
            "upload_time_iso_8601": "2024-08-09T15:49:47.243771Z",
            "url": "https://files.pythonhosted.org/packages/bd/0c/a4f8cac2868e06c83ceb4e00e8e50df395596e794ac54678111eafa00d57/django_readonly_field-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-09 15:49:47",
    "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.29376s