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
Close
Hashes for django-readonly-model-1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea99ff693c8b757371ff56397fb1d057e1a81f913c30bb46d0b67540f05a8bfc |
|
MD5 | f518e9115b0594dc8187e8a2ade41b4a |
|
BLAKE2b-256 | b4f3556598f1533b7fdca7f32a7c3d8c2f79d74fd72c3eea630dd2e87ba30855 |
Close
Hashes for django_readonly_model-1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd60fe234f530d4bd60a23d801cfd6f4b6e8652f2d38377944fdfb47e7bbfa44 |
|
MD5 | 58ecc23d8cc50f8d13049bfdf519310a |
|
BLAKE2b-256 | b0917ad69957916da625bc1dbcd4d0637423cfefbb2eee3c9899be2ba87d8c16 |