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, 1.10
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.2 (2016-07-31)
Fixed update missing when _local_last_updated could be set even when it wasn’t updated
Fixed update missing from integer rounding in time comparison
Fixed CachedDict.__repr__ so it works for other subclasses of CachedDict than ModelDict (don’t assume self.model exists)
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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90faf7b7df1300abec7994d8e9104d6d1cbce8dfe9b4e1a926751182017586b3 |
|
MD5 | 757c33d34b6af69e715ab993813ddfd9 |
|
BLAKE2b-256 | 079f2335ce9142cedcb18dd265468390f5dab72d0c6dccbd725964fbd8a40412 |
Hashes for django_modeldict_yplan-1.5.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97c646e405a955ef4238c2aa342ccc00a26ce55f122f5d162665b984dbae6237 |
|
MD5 | 8d516be577bef8626575d4155097709f |
|
BLAKE2b-256 | dd39da4ba405654ede3f1ef14a73d1b675fcf25b8b71918aed7571bf91af37b0 |