The easiest way to create read-only models for django
Project description
django-readonly-model
The easiest way to create read-only models
Installation
Install using pip
:
pip install django-readonly-model
Add 'readonly_model'
to your INSTALLED_APPS
setting:
INSTALLED_APPS = [
...
'readonly_model',
]
Example
Declare a model to read:
from django.db import models
class Directory(models.Model):
class Meta:
read_only_model = True
We can read data from the model but we cannot write:
>>> from app.models import Directory
>>> Directory.objects.count()
0
>>> Directory.objects.create(name='kg')
...
readonly_model.exceptions.ReadOnlyModel: Model 'app.models.Directory' is read-only
You cannot write but you can load data from fixtures:
$ python3 manage.py loaddata fixtures/directory.json
>>> from app.models import Directory
>>> Directory.objects.count()
3
When is it needed?
-
When you want to protect the model from accidental recording.
-
When you have some data that cannot be changed programmatically (for example, various directories).
-
When you need to use a read-only model from a database that you cannot write to it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-readonly-model-1.2.tar.gz
.
File metadata
- Download URL: django-readonly-model-1.2.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea99ff693c8b757371ff56397fb1d057e1a81f913c30bb46d0b67540f05a8bfc |
|
MD5 | f518e9115b0594dc8187e8a2ade41b4a |
|
BLAKE2b-256 | b4f3556598f1533b7fdca7f32a7c3d8c2f79d74fd72c3eea630dd2e87ba30855 |
File details
Details for the file django_readonly_model-1.2-py3-none-any.whl
.
File metadata
- Download URL: django_readonly_model-1.2-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd60fe234f530d4bd60a23d801cfd6f4b6e8652f2d38377944fdfb47e7bbfa44 |
|
MD5 | 58ecc23d8cc50f8d13049bfdf519310a |
|
BLAKE2b-256 | b0917ad69957916da625bc1dbcd4d0637423cfefbb2eee3c9899be2ba87d8c16 |