{ "info": { "author": "Thomas Khyn", "author_email": "thomas@ksytek.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Database", "Topic :: Software Development" ], "description": "django-idmap\n============\n\n|copyright| 2014-2017 Thomas Khyn\n|copyright| 2009 David Cramer\n\nAn identity mapper for the Django ORM. This is a fork of django-idmapper_,\nwhich is no longer maintained.\n\n``django-idmap`` has been tested against django 1.8, 1.11 and 2.0 and the\nlatest minor versions of Python 2 and 3 (Django 2.0 only supports Python 3).\n\nIf you like django-gm2m and are looking for a way to thank me and/or encourage\nfuture development, here is my BTC or BCH donation address:\n``1EwENyR8RV6tMc1hsLTkPURtn5wJgaBfG9``.\n\n\nWhat is it?\n-----------\n\n``django-idmap`` is a Django application which:\n\n- loads only once the instances in memory the first time they are needed\n- shares them throughout your interpreter until the request is finished\n\nIndeed, the default Django behavior is to expose different instances for the\nsame database entry between the start and the end of the request. It has one\nmain consequence: the temporary attributes you may set are lost if you want\nto access the same database object in another place in your code.\n\n.. warning::\n\n Deserialization (such as from the cache) will *not* use the identity mapper.\n\nTested with django 1.8+ and latest minor versions of python 2 and 3.\n\nInstallation\n------------\n\nAs straightforward as it can be, using pip::\n\n pip install django-idmap\n\nYou also need to add ``'idmap'`` to the ``INSTALLED_APPS`` setting.\n\n\nQuick start\n-----------\n\nTo enable the identity mapper for a model, you simply need to make it inherit\nfrom ``idmap.models.IdMapModel`` instead of ``django.db.models.Model``.\n\n.. tip::\n\n You can import ``idmap.models`` as you would import ``django.db.models``.\n ``idmap.models`` exposes all that is exposed by ``django.db.models`` plus\n the ``IdMapModel`` model class.\n\nYou may of course mix and match ``IdMapModel`` and ``Model``::\n\n from idmap import models\n\n class MyModel(models.IdMapModel):\n name = models.CharField(...)\n fkey = models.ForeignKey('Other', on_delete=models.CASCADE)\n\n class Other(models.Model):\n name = models.CharField(...)\n\n2 caching modes are available:\n\n- Weak references mode: the instance will be removed from the cache once there\n are no more references to it. This is the default behavior\n- Strong references mode: the instance will be loaded only once from the\n database and will be removed from the cache when it is flushed\n\nIf you want to use strong references for a particular model, simply set\n``use_strong_refs`` to ``True`` in the derived model class' ``Meta``::\n\n from idmap import models\n\n class MyModel(models.IdMapModel):\n class Meta:\n use_strong_refs = True\n [...]\n\n\nManual operations\n-----------------\n\nIn most cases, that's all there is to do with ``django-idmap``. Sometimes, you\nmay need to flush the cache manually before the request is finished.\n\nYou can use:\n\n- ``idmap.flush()`` to erase the whole cache\n- ``IdMapModel.flush_instance_cache()`` to erase the cache for one model\n- ``IdMapModel.flush_cached_instance(instance)`` to erase one instance\n from the cache\n\nSignals\n-------\n\n``idmap.signals.pre_flush`` and ``idmap.signals.post_flush`` are sent before -\nrespectively after - the cache is flushed. Connect handlers to these if you\nneed to run code at these moments.\n\n.. warning:\n\n ``pre_flush`` and ``post_flush`` are only sent when the ``flush`` function\n is used or when the cache is automatically flushed (when the request ends).\n\n\n``django-idmap`` flushes the cache when the ``request_finished`` or\n``post_migrate`` signal are sent. This default behavior may be modified (at\nyour own risk!) by disconnecting the ``idmap.signals.flush_idmap`` handler\nfrom these signals.\n\n\nMultiple database support\n-------------------------\n\nIn some cases, you may need to store instances of the same model in several\ndatabases. It is possible to tell ``django-idmap`` to also take the database\ninto account when creating or getting instances::\n\n class MyModel(models.IdMapModel):\n class Meta:\n multi_db = True\n [...]\n\nThis way, ``instance1_1`` with primary key ``1`` in database ``db1`` will be\ndifferent from ``instance2_1`` with primary key ``1`` in database ``db2``::\n\n >>> MyModel.objects.using('db1').create(pk=1)\n >>> MyModel.objects.using('db2').create(pk=1)\n >>> idmap.flush()\n >>> instance1_1 = MyModel.objects.using('db1').get(pk=1)\n >>> instance2_1 = MyModel.objects.using('db2').get(pk=1)\n >>> assert instance1_1 is instance 2_1\n AssertionError\n\nWhen using multiple databases, you may also flush only one database by\nproviding its name to ``idmap.flush()``::\n\n >>> idmap.flush('db1')\n\nwill only flush instances that were retrieved using the database ``db1``.\n``IdMapModel.flush_instance_cache`` can also take a ``db`` argument.\n\nSimilarly, a keyword-argument ``db`` is provided when the ``pre_flush`` and\n``post_flush`` signals are sent. ``db`` is ``None`` if all databases are\nflushed (i.e. if no database alias was provided).\n\n\nProxy models\n------------\n\nAll instances of models and proxy models using the same base concrete class\n(let's call this a proxy family) are stored in the same cache, and are\naccessible through all the members of the proxy family::\n\n >>> class MyProxyModel(MyModel):\n >>> class Meta:\n >>> proxy = True\n >>> original = MyModel.objects.create(pk=1)\n >>> proxy = MyProxyModel.objects.create(pk=2)\n >>> assert original is MyProxyModel.get(pk=1)\n\n\nInheritance catch-ups\n---------------------\n\nIn case you need to use a custom manager or custom metaclass on a model based\non ``IdMapModel``, you need to derive them from ``idmap``'s own manager and\nmetaclass::\n\n >>> class MyModelBase(models.IdMapModelBase):\n >>> [...]\n >>> class MyManager(models.IdMapManager):\n >>> [...]\n >>> class MyModel(models.IdMapModel,\n metaclass=MyModelBase): # on python 3\n >>> __metaclass__ = MyModelBase # on python 2\n >>> objects = MyManager()\n\n\nReferences\n----------\n\nDavid Cramer's django-idmapper_\n\nOriginal code and concept: http://code.djangoproject.com/ticket/17\n\n.. |copyright| unicode:: 0xA9\n.. _django-idmapper: https://github.com/dcramer/django-idmapper\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/tkhyn/django-idmap", "keywords": "django", "license": "", "maintainer": "", "maintainer_email": "", "name": "django-idmap", "package_url": "https://pypi.org/project/django-idmap/", "platform": "", "project_url": "https://pypi.org/project/django-idmap/", "project_urls": { "Homepage": "https://bitbucket.org/tkhyn/django-idmap" }, "release_url": "https://pypi.org/project/django-idmap/1.0.3/", "requires_dist": null, "requires_python": "", "summary": "An identity mapper for the Django ORM", "version": "1.0.3" }, "last_serial": 3399107, "releases": { "0.3": [ { "comment_text": "", "digests": { "md5": "4d44413234ea1f4c57b0eeb61fce7149", "sha256": "5e6e1b85ef6e551764c4a74dcaa3a1c631b453916c780a3b16cf112dd9c5472c" }, "downloads": -1, "filename": "django-idmap-0.3.zip", "has_sig": false, "md5_digest": "4d44413234ea1f4c57b0eeb61fce7149", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13303, "upload_time": "2014-10-06T01:50:15", "url": "https://files.pythonhosted.org/packages/49/98/f94fcda5472b03690a3d8da2a3fe85b8fa8e1e2ee49b27a4e2c265c8e041/django-idmap-0.3.zip" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "8e6ad5a3b4e11a6b55f9dcdbb938aa62", "sha256": "e8963f6c7d6b65952ffcbed91c0dd79fe96b7db7b9aa7c9c29da703c0013ffb9" }, "downloads": -1, "filename": "django-idmap-0.3.1.zip", "has_sig": false, "md5_digest": "8e6ad5a3b4e11a6b55f9dcdbb938aa62", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13409, "upload_time": "2014-10-06T03:47:08", "url": "https://files.pythonhosted.org/packages/4d/4b/1efed154fcc6264d1cc0a2acacd2ddddfe8111bb7b45612ea2317c0ab65f/django-idmap-0.3.1.zip" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "d48bfec8ff8c1b43f866c9e478225de9", "sha256": "8d5debbe390d0656de4dd436d221571f0ffa7ed6ea2ab501ba6559a70d5f6f12" }, "downloads": -1, "filename": "django-idmap-0.3.2.zip", "has_sig": false, "md5_digest": "d48bfec8ff8c1b43f866c9e478225de9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13884, "upload_time": "2014-12-11T10:08:05", "url": "https://files.pythonhosted.org/packages/dc/3d/173b2b405a25d6150159c3f2041b51a47b28dbea87ca58a8345a656f286a/django-idmap-0.3.2.zip" } ], "0.3.3": [ { "comment_text": "", "digests": { "md5": "6a75ee5824a7b799ccee660cbe46ea26", "sha256": "162dbc3710e228a3e13e7812a83f14c495ffcb403b3c76fadb162824d67770ae" }, "downloads": -1, "filename": "django-idmap-0.3.3.zip", "has_sig": false, "md5_digest": "6a75ee5824a7b799ccee660cbe46ea26", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14177, "upload_time": "2015-06-09T22:23:24", "url": "https://files.pythonhosted.org/packages/3d/d7/6641d01b056d395482c9ff3e90b324eaf567d53be0dafca2c32f64697858/django-idmap-0.3.3.zip" } ], "0.3c1": [ { "comment_text": "", "digests": { "md5": "ee608f35be99a5f7c05687bd7ba79eec", "sha256": "a407c376a73cd9667b528bb80ac8c2968b4e95a00ef9d9cd0c7062287ec06642" }, "downloads": -1, "filename": "django-idmap-0.3c1.zip", "has_sig": false, "md5_digest": "ee608f35be99a5f7c05687bd7ba79eec", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13366, "upload_time": "2014-09-28T19:31:12", "url": "https://files.pythonhosted.org/packages/e2/27/2bb38eafe7a83966f4cb99f15c29557af1676a41433de163e26ba520fc69/django-idmap-0.3c1.zip" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "e1586baa73cb83b257fb2f03724b7318", "sha256": "bfa538d8d06a3fbc660d2da581b4a4877cc5bbe1b82f1aacdd09168f5e2ce85a" }, "downloads": -1, "filename": "django-idmap-0.4.zip", "has_sig": false, "md5_digest": "e1586baa73cb83b257fb2f03724b7318", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14159, "upload_time": "2015-12-08T12:35:27", "url": "https://files.pythonhosted.org/packages/06/ed/fc8d048c6b9e41bbf3bc5570f3c127270bec835f2f09ff4557fcda8d41da/django-idmap-0.4.zip" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "e2171208f8e10465fb36eca4e8408327", "sha256": "e54adc9976e0c8517e02ff3e1d451f3b4c7a0fc47043562c8e10f9603a1d6ecf" }, "downloads": -1, "filename": "django-idmap-0.4.1.zip", "has_sig": false, "md5_digest": "e2171208f8e10465fb36eca4e8408327", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14253, "upload_time": "2016-01-19T02:01:54", "url": "https://files.pythonhosted.org/packages/05/46/35c7af903806f75dbfa0c9b2d0f26aa1093fef9711f3cabc14e8a3c8b659/django-idmap-0.4.1.zip" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "3ec25fcc50a4580a60b0352938862d09", "sha256": "39308238363070ecfa9bb83179dacf63ab9a8f43e2b86885fd61b3c3a4ac6b61" }, "downloads": -1, "filename": "django-idmap-1.0.tar.gz", "has_sig": false, "md5_digest": "3ec25fcc50a4580a60b0352938862d09", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12621, "upload_time": "2017-05-21T13:48:02", "url": "https://files.pythonhosted.org/packages/0b/e9/d9293c4b83e95d5904889883483a52b680c78cba724ca34d2dca9b37e89a/django-idmap-1.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "8fdcc0fb5a836404edffacd3f033f8c5", "sha256": "bc76511b10c9f294083b05a2c33f50375c41589b4176d46dd67925327736b7f9" }, "downloads": -1, "filename": "django-idmap-1.0.1.tar.gz", "has_sig": false, "md5_digest": "8fdcc0fb5a836404edffacd3f033f8c5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12683, "upload_time": "2017-09-18T01:43:02", "url": "https://files.pythonhosted.org/packages/bf/e5/9ced8151a96a750aa0594e4464a09c152b365103eddf431c6398d5c0ff16/django-idmap-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "9d137b20d1d83ce0b067f13f00e278f4", "sha256": "82804aa44a834f6143d4b2e865b9448cc763372c33058d0555ef18c7df16db82" }, "downloads": -1, "filename": "django-idmap-1.0.2.tar.gz", "has_sig": false, "md5_digest": "9d137b20d1d83ce0b067f13f00e278f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13104, "upload_time": "2017-10-10T07:56:02", "url": "https://files.pythonhosted.org/packages/5c/a3/b1495419aed6b560034a1c4135a3c3e42610ff6c1440b42910051870d6e1/django-idmap-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "d0a78369460b985552b720760ffe3189", "sha256": "0b067d0f101c97f35ed14c244a69bf4dfe1c138a99a55717ed345323c5af3163" }, "downloads": -1, "filename": "django-idmap-1.0.3.tar.gz", "has_sig": false, "md5_digest": "d0a78369460b985552b720760ffe3189", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13192, "upload_time": "2017-12-07T22:18:56", "url": "https://files.pythonhosted.org/packages/7d/28/1658c8d12807b2138d0a7dc15b6c9cf70b99860609ba9973081d8f2b5403/django-idmap-1.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d0a78369460b985552b720760ffe3189", "sha256": "0b067d0f101c97f35ed14c244a69bf4dfe1c138a99a55717ed345323c5af3163" }, "downloads": -1, "filename": "django-idmap-1.0.3.tar.gz", "has_sig": false, "md5_digest": "d0a78369460b985552b720760ffe3189", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13192, "upload_time": "2017-12-07T22:18:56", "url": "https://files.pythonhosted.org/packages/7d/28/1658c8d12807b2138d0a7dc15b6c9cf70b99860609ba9973081d8f2b5403/django-idmap-1.0.3.tar.gz" } ] }