Skip to main content

Stores a model as a dictionary

Project description


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:

  • Python: 2.7
  • Django: 1.7, 1.8


Install it with pip (or easy_install):

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
    >>> KeyError

    # Sets supported
    settings['foo'] = 'hello'

    # Fetch the current value using normal dictionary access
    >>> 'hello'

# ...or by normal model queries
>>> 'hello'


Pending Release

  • Forked by YPlan

1.4.1 (2012-12-04)

  • Last release by Disqus

Project details

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page