Stores a model as a dictionary
Project description
django-modeldict
ModelDict is a very efficient way to store things like settings in your database. The entire model is transformed into a dictionary (lazily) as well as stored in your cache. It’s invalidated only when it needs to be (both in process and based on CACHE_BACKEND).
It was originally created by Disqus, but due to the inactivity we at YPlan have taken over maintenance on this fork.
Requirements
Tested with all combinations of:
- Python: 2.7, 3.5
- Django: 1.8, 1.9
Install
Install it with pip:
pip install django-modeldict-yplan
Make sure you pip uninstall django-modeldict first if you’re upgrading from the original to this fork - the packages clash.
Example Usage
# You'll need a model with fields to use as key and value in the dict class Setting(models.Model): key = models.CharField(max_length=32) value = models.CharField(max_length=200) # Create the ModelDict... settings = ModelDict(Setting, key='key', value='value', instances=False) # And you can treat it like a normal dict: # Missing values = KeyError settings['foo'] >>> KeyError # Sets supported settings['foo'] = 'hello' # Fetch the current value using normal dictionary access settings['foo'] >>> 'hello' # ...or by normal model queries Setting.objects.get(key='foo').value >>> 'hello'
History
Pending release
- Any new changes will go here
1.5.0 (2016-01-11)
- Forked by YPlan
- Fixed concurrency TOCTTOU bug for threaded Django servers.
- Stopped including the ‘tests’ directory in package
- Django 1.8 and 1.9 supported.
- Python 3 support added.
- Fixed setdefault() to return the value that was set/found, as per normal dict semantics. Thanks @olevinsky.
1.4.1 (2012-12-04)
- Last release by Disqus
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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size django_modeldict_yplan-1.5.0-py2.py3-none-any.whl (11.6 kB) | File type Wheel | Python version 2.7 | Upload date | Hashes View |
Filename, size django-modeldict-yplan-1.5.0.tar.gz (13.0 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for django_modeldict_yplan-1.5.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ab4e58e3cadd287e9aed68363d9475b14b11e2317e45f9398288321dd126bda |
|
MD5 | cf95522cbe770a8de8cb519a97b8152a |
|
BLAKE2-256 | 0f8594bce2a4891ef160ba7d72ed79abbdfb97f29de09f2cf0ddf4d0cafad562 |
Close
Hashes for django-modeldict-yplan-1.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3b64ab145964f77f70a46fa87e7d85113150a8fd91ecf25b1a24ffd9cb88488 |
|
MD5 | b0b6949533d22eec157e12e6630236c4 |
|
BLAKE2-256 | cae33293b141d7dfa5a09aa4b91594c7f1875a22ea6cef4e762de3576a1146f0 |