{ "info": { "author": "Shaifali Agrawal", "author_email": "agrawalshaifali09@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.8", "Framework :: Django :: 1.9", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.5" ], "description": "***********************\ndjango-softdelete-it\n***********************\n\nAdd soft-delete functionality to desired models.\n\nQuick start\n############\n\nFollow steps mentioned below to add ``soft-delete`` feature in any model of your django app.\n\n1. ``pip install django-softdelete-it``\n2. Add ``soft_delete_it`` to your INSTALLED_APPS setting like this: ::\n\n INSTALLED_APPS = [\n ...\n 'soft_delete_it',\n ]\n3. Import ``SoftDeleteModel`` from soft_delete_it app to your model file like this: ::\n\n from soft_delete_it import SoftDeleteModel\n\n4. Inherit ``SoftDeleteModel`` class to your model class. It will add following features:\n - ``objects`` manager's behavior will change such that:\n - ``delete()`` method which will soft delete instances\n - will always return return only 'non soft deleted' objects\n - ``hard_delete()``` method to hard delete the objects\n - ``all_objects`` manager:\n - will always return both soft deleted and non soft deleted objects\n - ``hard_delete()`` method to hard delete the objects\n - ``only_deleted()`` method to return only soft deleted objects\n - ``undelete()`` method to un-delete soft-deleted objects\n\nExample\n**************\n::\n\n from django.db import models\n from soft_delete_it.models import SoftDeleteModel\n\n\n class Author(SoftDeleteModel):\n name = models.CharField(max_length=50)\n dob = models.DateField()\n\n\n class Article(SoftDeleteModel):\n title = models.CharField(max_length=50)\n body = models.TextField(null=True)\n author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='articles')\n\n\n Bob = Author.objects.create(name='bob', dob='2000-12-12')\n John = Author.objects.create(name='john', dob='1990-10-12')\n\n Author.objects.all() # return QuerySet with 2 objects\n Bob.delete() # Bob is soft-deleted\n Author.objects.all() # return QuerySet with 1 object, John\n Author.all_objects.all() # return QuerySet with 2 object, Bob and John\n Bob.undelete() # un-deletes Bob object\n Author.objects.all() # return QuerySet with 2 objects\n\n\n article1 = Article(title='Bob The Builder', body='')\n article1.author = Bob\n article1.save()\n\n Article.objects.all() # return QuerySet with 1 object, article1\n\n Bob.delete() # soft-deletes both Bob and article1 as Article's author field is on_delete_cascade and it Inherits SoftDeleteModel\n\n\nIf you are implementing a new ``Manager`` for a model, simply inherit ``SoftDeleteManager`` as well along with other Managers.\n\nIf you are implementing a new ``QuerySet`` for a model, you will need to do following:\n 1. Inherit ``SoftDeleteQuerySet``\n 2. Write Manager inheriting ``SoftDeleteManager`` which defines soft-delete functionality in it's ``__init__()`` method(as in the example) and override ``get_queryset()`` method(as in the example)\n 3. Write model class inheriting ``SoftDeleteModel`` and uses above new defined ``Manager`` method(as in the example)\n\n\nExample with QuerySet\n*****************************\n\nLets create a QuerySet for Article such that if no author is provided while creating a new article, one default author will be added in object.\n::\n\n #Creating a default author object first\n default_author = Author.objects.create(name='default')\n\n #Implementing QuerySet\n from soft_delete_it.models import SoftDeleteModel, SoftDeleteQuerySet, SoftDeleteManager\n\n class ArticleQuerySet(SoftDeleteQuerySet):\n\n def create(self, **kwargs):\n try:\n author = kwargs['author']\n except KeyError:\n kwargs['author'] = Author.objects.get(name='default')\n article = super(ArticleQuerySet, self).create(**kwargs)\n return article\n\n class ArticleManager(SoftDeleteManager):\n\n def __init__(self, *args, **kwargs):\n self.deleted_also = kwargs.get('deleted_also', False)\n super(ArticleManager, self).__init__(*args, **kwargs)\n\n def get_queryset(self):\n '''return all unsoft-deleted objects'''\n if self.deleted_also:\n return ArticleQuerySet(self.model)\n return ArticleQuerySet(self.model).filter(deleted=None)\n\n class Article(SoftDeleteModel):\n title = models.CharField(max_length=50)\n body = models.TextField(null=True)\n author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='articles')\n\n objects = ArticleManager.from_queryset(ArticleQuerySet)()\n all_objects = ArticleManager.from_queryset(ArticleQuerySet)(deleted_also=True)\n\n\nHow soft-deletion functionality is implemented:\n*****************************************************\n\n1. Create a new soft_delete app, whole code for soft-deletion functionality is implemented in its models.py file.\n2. An abstract ``SoftDeleteModel`` added which contains a ``deleted`` attribute which is a ``UUIDField``. It will hold ``None`` for undeleted object and a new ``uuid4`` for deleted objects.\n3. ``SoftDeleteQuerySet`` implemented to override default django's ``delete`` method to ``soft-delete`` objects instead of hard deleting them.\n4. ``undelete()``, ``hard_delete()``, ``only_deleted()`` methods are implemented in same QuerySet class to provide extra features.\n5. ``SoftDeleteManger`` implemented to use above QuerySet by overriding ``get_queryset()`` method.\n6. QuerySet's delete method is necessary to override to support ``bulk_delete`` feature.\n7. Call pre_delete and post_delete signals before and after the definition of above delete method.\n8. Use NestedObjects from django admin utils to soft-delete all related objects.\n9. Two managers, ``objects`` and ``all_objects`` to return undeleted, all objects are implemented.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/exploreshaifali/django-softdelete-it", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "django-softdelete-it", "package_url": "https://pypi.org/project/django-softdelete-it/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-softdelete-it/", "project_urls": { "Homepage": "https://github.com/exploreshaifali/django-softdelete-it" }, "release_url": "https://pypi.org/project/django-softdelete-it/0.1/", "requires_dist": null, "requires_python": "", "summary": "A simple Django app to add soft-delete functionality to desired models", "version": "0.1" }, "last_serial": 2393901, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "4a250ab4d59fbcdc17596d14f62ee64b", "sha256": "d311b75435e87b742fd5210979f5b57973343c1fea4125d0d9728e9819dc5438" }, "downloads": -1, "filename": "django_softdelete_it-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "4a250ab4d59fbcdc17596d14f62ee64b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8255, "upload_time": "2016-10-11T18:49:08", "url": "https://files.pythonhosted.org/packages/2d/e4/92d806df8aa68a4181d8f88613ae17a02710a043a1d2a6f9b844920a9248/django_softdelete_it-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "97f6c557377e7840d2bd25ea65a03f47", "sha256": "ea4f39205a6f8c0dd8fc0686c1f937674ae4b8fed23e861cc7c193f66d533016" }, "downloads": -1, "filename": "django-softdelete-it-0.1.tar.gz", "has_sig": false, "md5_digest": "97f6c557377e7840d2bd25ea65a03f47", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6637, "upload_time": "2016-10-11T18:49:11", "url": "https://files.pythonhosted.org/packages/54/23/db52ab9a513036d542d70bc9d68f453c3edd06377c1790551998798fc488/django-softdelete-it-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4a250ab4d59fbcdc17596d14f62ee64b", "sha256": "d311b75435e87b742fd5210979f5b57973343c1fea4125d0d9728e9819dc5438" }, "downloads": -1, "filename": "django_softdelete_it-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "4a250ab4d59fbcdc17596d14f62ee64b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8255, "upload_time": "2016-10-11T18:49:08", "url": "https://files.pythonhosted.org/packages/2d/e4/92d806df8aa68a4181d8f88613ae17a02710a043a1d2a6f9b844920a9248/django_softdelete_it-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "97f6c557377e7840d2bd25ea65a03f47", "sha256": "ea4f39205a6f8c0dd8fc0686c1f937674ae4b8fed23e861cc7c193f66d533016" }, "downloads": -1, "filename": "django-softdelete-it-0.1.tar.gz", "has_sig": false, "md5_digest": "97f6c557377e7840d2bd25ea65a03f47", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6637, "upload_time": "2016-10-11T18:49:11", "url": "https://files.pythonhosted.org/packages/54/23/db52ab9a513036d542d70bc9d68f453c3edd06377c1790551998798fc488/django-softdelete-it-0.1.tar.gz" } ] }