{ "info": { "author": "Beau Sorensen", "author_email": "mail@beausorensen.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Django Unchained\n\nProvides an easier way of overriding Django's default QuerySet, by default allowing you to tap into\nthe args and kwargs of any QuerySet method without overriding them all. The package also provides an\nintegration manager and injection manager for re-mapping queries sent to the ORM, or forcing all queries\nto contain a certain constraint. Unchain your Django app!\n\n\n## Installation\n\n```bash\npip install django-unchained\n````\n\nAlternatively, you can download the project and put the `client_errors` directory into \nyour project directory.\n\nAdd the following app to your project's `INSTALLED_APPS` in the `settings.py` file:\n\n````\n'unchained',\n````\n\n\n## Configuration\n\n* `UNCHAINED_ENABLE_INTEGRATION` enable ORM field mapping (optional, default `True`)\n* `UNCHAINED_ENABLE_INJECTION` enable ORM query injection (optional, default `True`)\n\n\n## Usage\n\nBy having any model inherit from the `unchained.IntegrationModel`, you can specify a `FIELD_MAP`\ndict attribute on the model, telling the ORM what fields to automatically map to another. This may \nalso be done dynamically if the value to any key begins with a `__`, which will then call to the \nmodel's `get_field_mapper` method to get the correct field.\n\n```python\nfrom django import models\nimport unchained\n\nclass Foo(unchained.IntegrationModel):\n FIELD_MAP = {\n 'old' : 'new',\n 'blah' : '__hey__there'\n }\n @classmethod\n def get_field_mapper(self, field):\n return 'dynamically%s' % self.FIELD_MAP.get(field)\n````\n\nThe `unchained.InjectionModel` will behave similarly, the model will need a `INJECTION_MAP` \ndict attribute to tell the ORM what to look for. The key represents the field, or partial field,\nto look for (since it may represent a variety of options), and the value represents the actual\nfield to use. If the value begins with a `__`, a prefix will be added by calling the model's \n`get_injection_prefix` method. It will always call a `get_injection_value` method on the model \nto find out what value should be used for the query.\n\n```python\nclass Bar(unchained.InjectionModel):\n INJECTION_MAP = {\n 'search' : 'actual_search_field',\n 'partial' : '__dont_know__yet'\n }\n @classmethod\n def get_injection_prefix(self):\n return 'icouldbedynamic'\n\n @classmethod\n def get_injection_value(self, field):\n if field == 'search':\n return 3\n elif field == 'partial':\n return 'heeeeeey'\n raise Exception\n````\n\nBoth classes can be combined using the `unchained.InjectIntegrateModel`\n\nIf you would like to override the base `unchained.UnchainedModel`, `unchained.UnchainedQuerySet`, \nor `unchained.UnchainedManager`, you will need to replace all three. (sorry, its a Django thing).\nYou can also set a models `objects` directly to your custom manager and then not need to override\nthe model itself. I tend to inherit from the custom model class as to save myself from repeating \ntoo much code. But its up to you.\n\n```python\nimport unchained\n\nclass SpecialQuerySet(unchained.UnchainedQuerySet)\n def _kwargs(self, **kwargs):\n # do something to the kwargs\n return kwargs\n\n def _args(self, *args):\n # do something to the args\n return args\n\nclass SpecialManager(unchained.UnchainedManager):\n def get_query_set(self):\n return SpecialQuerySet(self.model, using=self._db)\n\n# Optional\nclass SpecialModel(unchained.Model):\n objects = SpecialManager()\n\n class Meta:\n abstract = True\n````\n\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2011-2012 Beau Sorensen \n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/sorensen/django-unchained/downloads", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/sorensen/django-unchained", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "django-orm-unchained", "package_url": "https://pypi.org/project/django-orm-unchained/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-orm-unchained/", "project_urls": { "Download": "https://github.com/sorensen/django-unchained/downloads", "Homepage": "https://github.com/sorensen/django-unchained" }, "release_url": "https://pypi.org/project/django-orm-unchained/0.0.2/", "requires_dist": null, "requires_python": null, "summary": "Django integration manager for field renaming", "version": "0.0.2" }, "last_serial": 436339, "releases": { "0.0.2": [] }, "urls": [] }