{ "info": { "author": "Tom\u00e1s Fox", "author_email": "tomas.c.fox@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.10", "Framework :: Django :: 1.11", "Framework :: Django :: 1.8", "Framework :: Django :: 1.9", "Framework :: Django :: 2.0", "Framework :: Django :: 2.1", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "# django-deprecation\n\n[![build status](https://img.shields.io/travis/openbox/django-deprecation.svg)](https://travis-ci.org/openbox/django-deprecation)\n[![coverage](https://img.shields.io/codecov/c/github/openbox/django-deprecation.svg)](https://codecov.io/gh/openbox/django-deprecation)\n[![PyPI version](https://img.shields.io/pypi/v/django-deprecation.svg)](https://pypi.org/project/django-deprecation/)\n![python version](https://img.shields.io/pypi/pyversions/django-deprecation.svg)\n![django version](https://img.shields.io/pypi/djversions/django-deprecation.svg)\n\nDeprecate django fields and make migrations without breaking existing code.\n\n\n## Install\n\n```bash\npip install django-deprecation\n```\n\n\n## Usage\n\n### TL;DR\n\n```py\n# Before:\nclass Album(models.Model):\n name = models.CharField(max_length=50)\n\n\n# After:\nclass Album(models.Model):\n name = DeprecatedField('title')\n title = models.CharField(max_length=50)\n\n\nassert album.name == album.title\nassert list(Album.objects.filter(name='foo')) == list(Album.objects.filter(title='foo'))\n```\n\n### Long explanation\n\nLet's suppose we have the following models:\n\n```py\nfrom django.db import models\n\n\nclass Musician(models.Model):\n name = models.CharField(max_length=50)\n\n\nclass Album(models.Model):\n musician = models.ForeignKey(Musician, on_delete=models.CASCADE)\n name = models.CharField(max_length=100)\n```\n\n\nNow, for some reason, let's suppose we want to rename the field `Album#musician` to `Album#artist`.\n\nSo we make the migration using the\n[RenameField](https://docs.djangoproject.com/en/1.11/ref/migration-operations/#renamefield)\noperation. The problem is that any existing code that used the old field would break.\n\nWe could create a property as an alias:\n\n```py\nclass Album(models.Model):\n artist = models.ForeignKey(Musician, on_delete=models.CASCADE)\n name = models.CharField(max_length=100)\n\n @property\n def musician(self):\n return self.artist\n\n @musician.setter\n def musician(self, value):\n self.artist = value\n```\n\nBut any code using\n[QuerySet#filter](https://docs.djangoproject.com/en/2.0/ref/models/querysets/#filter)\nwould break if it uses the `musician` field.\n\nThis is where `django-deprecation` comes handy.\nWe set the `musician` field as a `DeprecatedField` and point it to the `artist` field:\n\n```py\nfrom django_deprecation import DeprecatedField\n\n\nclass Album(models.Model):\n artist = models.ForeignKey(Musician, on_delete=models.CASCADE)\n musician = DeprecatedField('artist')\n name = models.CharField(max_length=100)\n```\n\n\nNow, the following code snippet will work:\n\n```py\nfrom .models import Album, Musician\n\nalbum = Album.objects.first()\nassert album.musician == album.artist\n\nnew_musician = Musician.objects.create(\n first_name='John',\n last_name='Doe',\n instrument='Guitar',\n)\nalbum.musician = new_musician\nassert album.artist == new_musician\n\nnew_musician_album = Album.objects.filter(\n musician=new_musician,\n).first()\nnew_artist_album = Album.objects.filter(\n artist=new_musician,\n).first()\nassert new_musician_album == new_artist_album\n```\n\nIf you want to control how to report the error,\nreplace the `DeprecatedField.warn` function with a custom one:\n\n```py\nfrom django_deprecation import DeprecatedField\n\n\ndef warn_function(message):\n # do stuff\n import warnings\n warnings.warn(message, DeprecationWarning)\n\n\nDeprecatedField.warn = warn_function\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/openbox/django-deprecation", "keywords": "django deprecation deprecated field migrate alias", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-deprecation", "package_url": "https://pypi.org/project/django-deprecation/", "platform": "", "project_url": "https://pypi.org/project/django-deprecation/", "project_urls": { "Homepage": "https://github.com/openbox/django-deprecation" }, "release_url": "https://pypi.org/project/django-deprecation/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "Deprecate django fields and make migrations without breaking existing code.", "version": "0.1.1" }, "last_serial": 4250513, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "9d378fd5c68315e8e8c0021a67b175cc", "sha256": "089455e7a6a6fa34884222e9746adb8e875c11d3b7aa0a88c0f7e99dbd44484a" }, "downloads": -1, "filename": "django_deprecation-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "9d378fd5c68315e8e8c0021a67b175cc", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3677, "upload_time": "2018-09-04T20:11:13", "url": "https://files.pythonhosted.org/packages/86/11/baa0de99d09ec24b85283bb42a3387fe49fc28d3f796db9df2118e39aa0b/django_deprecation-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4767418d9f587f900f5036fef85ff9cb", "sha256": "0ae3cc4ed4164a6a7e425763c782b9175f689fcd146dd99fa9453ebaf1e34fa2" }, "downloads": -1, "filename": "django-deprecation-0.1.0.tar.gz", "has_sig": false, "md5_digest": "4767418d9f587f900f5036fef85ff9cb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3634, "upload_time": "2018-09-04T20:11:14", "url": "https://files.pythonhosted.org/packages/31/fd/61d8d2329a10d1108e98ad5bb389ff9c6df0aca70eb1f62f41fb07ea901b/django-deprecation-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "ae38c6228747738d6490d2bf45b91bb8", "sha256": "9be8f772c0e7b7acbf1646bea6fc2242ba36404a42bd46b29e812ff3dfd8acc4" }, "downloads": -1, "filename": "django_deprecation-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ae38c6228747738d6490d2bf45b91bb8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3886, "upload_time": "2018-09-07T23:10:45", "url": "https://files.pythonhosted.org/packages/bf/a9/42c43bc1ceecdeccb0954a245b26bf987e2bd91c110b34557b89dcdc495f/django_deprecation-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cdaae44e62e4b5612eb35433032aa6ac", "sha256": "6dfe3f91914947ba8bb2eb58b4fe26fcac710301c3f533439f4362f5116f6e57" }, "downloads": -1, "filename": "django-deprecation-0.1.1.tar.gz", "has_sig": false, "md5_digest": "cdaae44e62e4b5612eb35433032aa6ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3960, "upload_time": "2018-09-07T23:10:47", "url": "https://files.pythonhosted.org/packages/4a/53/aeb158bd41298b3699a8019535aff4c90063250a95ccfd888c59ae176ee0/django-deprecation-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ae38c6228747738d6490d2bf45b91bb8", "sha256": "9be8f772c0e7b7acbf1646bea6fc2242ba36404a42bd46b29e812ff3dfd8acc4" }, "downloads": -1, "filename": "django_deprecation-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ae38c6228747738d6490d2bf45b91bb8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3886, "upload_time": "2018-09-07T23:10:45", "url": "https://files.pythonhosted.org/packages/bf/a9/42c43bc1ceecdeccb0954a245b26bf987e2bd91c110b34557b89dcdc495f/django_deprecation-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cdaae44e62e4b5612eb35433032aa6ac", "sha256": "6dfe3f91914947ba8bb2eb58b4fe26fcac710301c3f533439f4362f5116f6e57" }, "downloads": -1, "filename": "django-deprecation-0.1.1.tar.gz", "has_sig": false, "md5_digest": "cdaae44e62e4b5612eb35433032aa6ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3960, "upload_time": "2018-09-07T23:10:47", "url": "https://files.pythonhosted.org/packages/4a/53/aeb158bd41298b3699a8019535aff4c90063250a95ccfd888c59ae176ee0/django-deprecation-0.1.1.tar.gz" } ] }