Stores a model as a dictionary
Project description
================
django-modeldict
================
.. image:: https://img.shields.io/pypi/v/django-modeldict-yplan.svg
:target: https://pypi.python.org/pypi/django-modeldict-yplan
.. image:: https://travis-ci.org/adamchainz/django-modeldict.svg?branch=master
:target: https://travis-ci.org/adamchainz/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 <https://github.com/disqus/django-modeldict>`_, but due to the inactivity we at YPlan have taken over maintenance on this fork.
Requirements
------------
Tested with all combinations of:
* Python: 3.6
* Django: 1.11, 2.0, 2.1
Python 3.4+ supported.
Install
-------
Install it with **pip**:
.. code-block:: bash
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
-------------
.. code-block:: python
# 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
---------------
.. Add new release notes below here
2.0.1 (2019-02-15)
------------------
* No functional changes. This is a re-release of version 2.0.0 to fix immutable
metadata on PyPI so that Pip on Python 2 doesn't pick up the Python 3 only
2.X series. **Version 2.0.0 will be pulled from PyPI on 2019-02-29.**
2.0.0 (2019-01-29)
------------------
----
**This version is due to be pulled from PyPI, please use version 2.0.1 as per
its above release note.**
----
* Drop Python 2 support, only Python 3.4+ is supported now.
* Drop Django 1.8, 1.9, and 1.10 support. Only Django 1.11+ is supported now.
* Remove ``iteritems()``, ``iterkeys()``, and ``itervalues()`` methods from
``ModelDict``, and move ``items()``, ``keys()``, and ``values()`` to Python 3
semantics, returning iterators rather than lists.
* Include LICENSE file in wheel.
* Tested with Django 2.1 (no changes were needed for compatibility).
1.5.4 (2016-10-28)
------------------
* Fixed a race condition in threaded code. See https://github.com/adamchainz/django-modeldict/pull/40 for a detailed
explanation. Thanks @Jaidan.
1.5.3 (2016-09-20)
------------------
* Stop rounding ``time.time()`` down to the nearest integer, so we are more fine grained around expiration. It might
also fix a subtle timing bug around re-fetching the remote cache unnecessarily.
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
django-modeldict
================
.. image:: https://img.shields.io/pypi/v/django-modeldict-yplan.svg
:target: https://pypi.python.org/pypi/django-modeldict-yplan
.. image:: https://travis-ci.org/adamchainz/django-modeldict.svg?branch=master
:target: https://travis-ci.org/adamchainz/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 <https://github.com/disqus/django-modeldict>`_, but due to the inactivity we at YPlan have taken over maintenance on this fork.
Requirements
------------
Tested with all combinations of:
* Python: 3.6
* Django: 1.11, 2.0, 2.1
Python 3.4+ supported.
Install
-------
Install it with **pip**:
.. code-block:: bash
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
-------------
.. code-block:: python
# 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
---------------
.. Add new release notes below here
2.0.1 (2019-02-15)
------------------
* No functional changes. This is a re-release of version 2.0.0 to fix immutable
metadata on PyPI so that Pip on Python 2 doesn't pick up the Python 3 only
2.X series. **Version 2.0.0 will be pulled from PyPI on 2019-02-29.**
2.0.0 (2019-01-29)
------------------
----
**This version is due to be pulled from PyPI, please use version 2.0.1 as per
its above release note.**
----
* Drop Python 2 support, only Python 3.4+ is supported now.
* Drop Django 1.8, 1.9, and 1.10 support. Only Django 1.11+ is supported now.
* Remove ``iteritems()``, ``iterkeys()``, and ``itervalues()`` methods from
``ModelDict``, and move ``items()``, ``keys()``, and ``values()`` to Python 3
semantics, returning iterators rather than lists.
* Include LICENSE file in wheel.
* Tested with Django 2.1 (no changes were needed for compatibility).
1.5.4 (2016-10-28)
------------------
* Fixed a race condition in threaded code. See https://github.com/adamchainz/django-modeldict/pull/40 for a detailed
explanation. Thanks @Jaidan.
1.5.3 (2016-09-20)
------------------
* Stop rounding ``time.time()`` down to the nearest integer, so we are more fine grained around expiration. It might
also fix a subtle timing bug around re-fetching the remote cache unnecessarily.
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
File details
Details for the file django-modeldict-yplan-2.0.1.tar.gz
.
File metadata
- Download URL: django-modeldict-yplan-2.0.1.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d3fe67fccb557676ef2adae946853f498e15382a7d45440ac8a60c0f5107096 |
|
MD5 | f59c1f51933dc525d36b4a5634192638 |
|
BLAKE2b-256 | fba63b8bcaa8d40822ce70e7980bf630f991e483c8137399712e830494962333 |
File details
Details for the file django_modeldict_yplan-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: django_modeldict_yplan-2.0.1-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a783ab535b8e547cc4e192dbc0b99959f0ed6e705349ac437b9eba3761aa55c |
|
MD5 | 9077283d8a58a1505abe9015638532a3 |
|
BLAKE2b-256 | 599a866349a11236879cec67172fea32d6a2de744342d1770045c90304b5ea57 |