{ "info": { "author": "Vimal Aravindashan", "author_email": "vimal.aravindashan@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.8", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": "======================\nDjango GetOrCreatePlus\n======================\n\nDjango GetOrCreatePlus is a set of queryset mixins to create custom querysets that can:\n\n* Cache results of get_or_create() or update_or_create()\n\n* Always use get_or_create() when get() calls are made\n\n* Allow non-atomic get_or_create() to avoid nested transaction points\n\nQuick start\n-----------\n\n.. code:: python\n\n # models.py\n \n from django.db import models\n from django.core.cache import caches\n from getorcreateplus import CachedGetOrCreateMixin, AlwaysGetOrCreateMixin, NonAtomicGetOrCreateMixin\n \n \n # sample for CachedGetOrCreateMixin (see below for changes to be made in settings.py)\n class CachedQuerySet(CachedGetOrCreateMixin, models.QuerySet):\n pass\n \n class CachedManager(models.manager.BaseManager.from_queryset(CachedQuerySet)):\n use_for_related_fields = True\n \n class CachedImmutableModel(models.Model):\n foo = models.CharField(max_length=8)\n bar = models.IntegerField(null=True)\n \n objects = CachedManager()\n \n \n obj1, _ = CachedImmutableModel.objects.get_or_create(foo='FooBar') # fetches from db\n obj2, _ = CachedImmutableModel.objects.get_or_create(foo='FooBar') # hits cache\n \n \n class CachedMutableObject(models.Model):\n foo = models.CharField(max_length=8)\n bar = models.IntegerField(null=True)\n \n objects = CachedManager()\n \n def save(self, **kwargs):\n cache = caches[self._meta.model_name]\n cache.delete(self.pk)\n return super(CachedMutableObject, self).save(**kwargs)\n \n \n obj1, _ = CachedMutableModel.objects.get_or_create(foo='FooBar') # fetches from db\n obj1.bar = 1\n obj1.save() # invalidate object cache\n obj2, _ = CachedMutableModel.objects.get_or_create(foo='FooBar') # fetches from db\n obj3, _ = CachedMutableModel.objects.get_or_create(foo='FooBar') # hits cache\n \n \n # sample for NonAtomicGetOrCreateMixin\n class NonAtomicQuerySet(NonAtomicGetOrCreateMixin, models.QuerySet):\n pass\n \n class NonAtomicManager(models.manager.BaseManager.from_queryset(NonAtomicQuerySet)):\n use_for_related_fields = True\n \n class ParentQuerySet(NonAtomicQuerySet):\n def create(self, **kwargs):\n children = kwargs.pop('children', [])\n parent = super(ParentQuerySet, self).create(**kwargs)\n for child in children:\n parent.children.get_or_create(**child)\n return parent\n \n class ParentManager(models.manager.BaseManager.from_queryset(ParentQuerySet)):\n use_for_related_fields = True\n \n class ParentModel(models.Model):\n foo = models.CharField(max_length=8)\n \n objects = ParentManager()\n \n class ChildModel(models.Model):\n parent = models.ForeignKey(Parent, related_name='children')\n bar = models.CharField(max_length=8)\n \n objects = NonAtomicManager()\n \n \n from django.db import transaction\n \n with transaction.atomic():\n parent, _ = ParentModel.objects.get_or_create(foo='Foo', defaults={children: [{bar: 'Bar'}, {bar: 'Baz'}]})\n \n \n # samples for combining mixins CachedGetOrCreateMixin, AlwaysGetOrCreateMixin, NonAtomicGetOrCreateMixin\n class NonAtomicAlwaysQuerySet(NonAtomicGetOrCreateMixin, AlwaysGetOrCreateMixin, models.QuerySet):\n pass\n \n class AlwaysCachedQuerySet(AlwaysGetOrCreateMixin, CachedGetOrCreateMixin, models.QuerySet):\n pass\n \n class PlusQuerySet(CachedGetOrCreateMixin, AlwaysGetOrCreateMixin, NonAtomicGetOrCreateMixin, models.QuerySet):\n pass\n\n`CachedGetOrCreateMixin` uses Django caches. The keys are cached to the\n`default` cache, and the objects are cached using alias\n`model._meta.model_name`.\n\n**NOTE:** If you have models by the same name in different apps both using\nCachedGetOrCreateMixin, this will fail.\n\n.. code:: python\n\n # settings.py\n # assuming use of django-connection-url (shameless self-plug)\n \n import connection_url\n \n CACHES = {\n 'default': connection_url.config('locmem:///'),\n 'cachedimmutablemodel': connection_url.config('REDIS_URL'),\n 'cachedmutablemodel': connection_url.config('MEMCACHED_URL'),\n }", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/f0r4y312/django-getorcreateplus", "keywords": "django get_or_create update_or_create get create update cache atomic non-atomic", "license": "Apache-2.0", "maintainer": null, "maintainer_email": null, "name": "django-getorcreateplus", "package_url": "https://pypi.org/project/django-getorcreateplus/", "platform": "any", "project_url": "https://pypi.org/project/django-getorcreateplus/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/f0r4y312/django-getorcreateplus" }, "release_url": "https://pypi.org/project/django-getorcreateplus/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Mixins to cache, force and/or use non-atomic Model.objects.get_or_create() calls.", "version": "0.1.0" }, "last_serial": 2475582, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "9f50e3d2366cdde89af35fbca9562c8e", "sha256": "c6514fc3e88b6585ad3eec0fac2252a3a956216610e3b08a3cb2f4a4f3695a45" }, "downloads": -1, "filename": "django_getorcreateplus-0.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "9f50e3d2366cdde89af35fbca9562c8e", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5930, "upload_time": "2016-11-22T06:46:58", "url": "https://files.pythonhosted.org/packages/d9/da/6d19644d51f488321f28f4433a443fa4bddfaa42e9887622b4707fe51837/django_getorcreateplus-0.1.0-py2-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9f50e3d2366cdde89af35fbca9562c8e", "sha256": "c6514fc3e88b6585ad3eec0fac2252a3a956216610e3b08a3cb2f4a4f3695a45" }, "downloads": -1, "filename": "django_getorcreateplus-0.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "9f50e3d2366cdde89af35fbca9562c8e", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5930, "upload_time": "2016-11-22T06:46:58", "url": "https://files.pythonhosted.org/packages/d9/da/6d19644d51f488321f28f4433a443fa4bddfaa42e9887622b4707fe51837/django_getorcreateplus-0.1.0-py2-none-any.whl" } ] }