Stores a model as a dictionary
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.
Tested with all combinations of:
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.
# 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'
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|django_modeldict_yplan-1.5.4-py2.py3-none-any.whl (13.5 kB) Copy SHA256 Checksum SHA256||2.7||Wheel||Oct 28, 2016|
|django-modeldict-yplan-1.5.4.tar.gz (14.9 kB) Copy SHA256 Checksum SHA256||–||Source||Oct 28, 2016|