{"id":18444652,"url":"https://github.com/Draup/draup_django","last_synced_at":"2025-04-07T23:33:08.457Z","repository":{"id":57423956,"uuid":"160629753","full_name":"Draup/draup_django","owner":"Draup","description":"Delete functionality for normalised models","archived":false,"fork":false,"pushed_at":"2024-01-24T06:12:10.000Z","size":165,"stargazers_count":7,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T06:23:17.312Z","etag":null,"topics":["cascade","delete","django","django-framework","foreign-keys","normalised-models","relational-databases"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/draup-django/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Draup.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-12-06T06:30:03.000Z","updated_at":"2024-09-28T03:15:02.000Z","dependencies_parsed_at":"2024-03-01T07:47:20.685Z","dependency_job_id":null,"html_url":"https://github.com/Draup/draup_django","commit_stats":null,"previous_names":["draup/draup_django","draup-zinnov/draup_django"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Draup%2Fdraup_django","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Draup%2Fdraup_django/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Draup%2Fdraup_django/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Draup%2Fdraup_django/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Draup","download_url":"https://codeload.github.com/Draup/draup_django/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223265482,"owners_count":17116373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cascade","delete","django","django-framework","foreign-keys","normalised-models","relational-databases"],"created_at":"2024-11-06T07:03:06.194Z","updated_at":"2024-11-06T07:03:07.517Z","avatar_url":"https://github.com/Draup.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# draup_django\n\n[![Downloads](https://pepy.tech/badge/draup-django)](https://pepy.tech/project/draup-django)\n\n### Delete, Update functionality for normalised models\n\n\n## Use-Case : \n\n  * `Draup Django` provide \n   stateful delete, update functionality at ORM(object relational mapping)level.\n  \n## Table of Content :\n  \n  * [Stateful Delete/Update](#stateful)\n     * [Get Affected Objects](#get-affected-objects)\n     * [Delete Object](#delete-object)\n     * [Update Object](#update-object)\n  * [Installation](#installation)\n\n\n## Stateful Delete/Update\n  * Below are functions inorder to get the stateful delete/update\n \n  ### Get Affected Objects\n   * List out all dependent objects(Prompt-Messages).\n   * `getAffectedObjects` takes input dict with id as key and reference of model.\n   \n   ```\n   Sample Input : ({'id':1},model_reference)\n   Output : Error_list(list),prompt messages(list)\n   ```\n   \n  ### Delete Object\n   * Delete object with all the dependent objects. \n   * `deleteObject` takes input dict with id and force_delete as key and reference of model.\n   \n   ```\n   Sample Input : ({'id':1,'force_delete':True},model_reference)\n   Output : Error_list(list)\n   ```\n   \n  ### Update Object \n   * Transferring Object dependencies from one object to another object.\n   * `updateObjectDependencies` takes input source,destination objects.\n   \n   ```\n   Sample Input : (source,destination)\n   Output : Error_list(list)\n   ```\n\n## Installation\n  * Use Pip to install the module\n  \n    ```\n    pip install draup-django\n    ```\n    \n## Usage :\n  * Sample model : \n      \n          class parent(models.Model):\n            name = models.CharField(max_length=100)\n            \n          class child(models.Model):\n            parent = models.ForeignKey(parent, on_delete=models.CASCADE) \n            name = models.CharField(max_length=100)\n      \n  *  Parent Table :\n  \n     | id     | Name      |\n     | ------ | --------- |\n     |  1     |  Alice    |\n     |  2     |  Tom      |\n  \n * Child Table :\n  \n     | id          | Name       |  parent_id    |\n     | ----------- |  --------- |-------------- |\n     |  1          |  Bob       |     1         |\n     |  2          |  Jack      |     2         | \n\n  \n  * Code :\n         \n         from draup_django import utility\n         m = models.parent\n\n         \"\"\"\n         Get Prompt Message\n         \"\"\"\n\n         error_list,prompt_message = utility.getAffectedObjects({'id':1},m)\n\n         \"\"\"\n         Deletion with all dependent objects\n         \"\"\"\n         error_list = utility.deleteObject({'id':1,'force_delete':True},m)\n\n         \"\"\"\n         Transferring Object dependencies\n         \"\"\"\n\n         source = m.objects.filter(id=1).first()\n         destination = m.objects.filter(id=2).first()\n         error_list = utility.updateObjectDependencies(source,destination)\n         \n  * Output :\n        Prompt Message of `getAffectedObjects` function\n        \n        [{'message': 'This object has been used in child 1 times.', 'model_name': 'child', 'Parent models': '', 'count': 1}] \n         \n  * **Note** : \n       -  Every function returns the error_list, and hence only the operation is successful only if it is empty. \n       -  According to above Child/Parent Table `updateObjectDependencies` function will transafer object dependency from `id:1` to `id:2` so parent_id of `Bob` will become `2`. \n  \n       - Updated Child Table: \n       \n         | id          | Name       |  parent_id    |\n         | ----------- |  --------- |-------------- |\n         |  1          |  Bob       |     2         |\n         |  2          |  Jack      |     2         |\n   \n## Limitation :\n   * `updateObjectDependencies` will not work in case of unique constraint,one to one field in model.\n   * Please feel free to share your thoughts and feedback at info@draup.com .\n  \n\n## About Draup :\n   \n  [Draup](https://draup.com) is an enterprise decision-making platform for global CXO leaders in sales and talent domains. Draup combines Artificial Intelligence with human curation to help organizations make data-driven strategic decisions. The platform is powered by machine- generated models, which are augmented by a team of analysts adding their learning-based insights to provide a 360-degree transactable view of their sales and talent ecosystem. We work on cutting edge technolgies and run highly complex algorithms on huge volumes of data. We also rely on open-sourcing which equips us with the right tools which allows us to find truly unique and innovate solutions to several problems.\n   \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDraup%2Fdraup_django","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDraup%2Fdraup_django","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDraup%2Fdraup_django/lists"}