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
New release notes here
1.5.1 (2016-06-13)
Fixed local cache never expiring if value was checked too often.
Use Django’s cache.set_many for more efficient storage.
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.
Source Distribution
Built Distribution
Hashes for django-modeldict-yplan-1.5.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e637cd274dbfe300ce40c742651d306e06a3cae49fd199391379b878a0d084c1 |
|
MD5 | 1a25333b49b6d0a2bd4f394806342092 |
|
BLAKE2b-256 | 1de9d359e936a6e40d164f99b0ef4d31bfb4a4b8e38502936fbd04bc4197412a |
Hashes for django_modeldict_yplan-1.5.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1758fe3b6df4719354e16fe66919a9589616481c798e4c40d1df8a6fb4926b0 |
|
MD5 | b5972fb8b28a3e3857e6f2f739694f73 |
|
BLAKE2b-256 | 2b4daca1c47e0ca64155c3b63551803fd18e63a01b6af2755f7366e6bc0e5b9f |