Skip to main content

Django Utility - Draup Labs

Project description

draup_django

Delete, Update functionality for normalised models

Use-Case :

  • Draup Django provide delete, update functionality for ORM(object relational mapping)level.

Table of Content :

Stateful Delete/Update

  • Below are functions inorder to get the stateful delete/update

Get Affected Objects

  • List out all dependent objects(Prompt-Messages).
  • getAffectedObjects takes input dict with id as key and reference of model.
Sample Input : ({'id':1},model_reference)
Output : Error_list(list),prompt messages(list)

Delete Object

  • Delete object with all the dependent objects.
  • deleteObject takes input dict with id and force_delete as key and reference of model.
Sample Input : ({'id':1,'force_delete':True},model_reference)
Output : Error_list(list)

Update Object

  • Transferring Object dependencies from one object to another object.
  • updateObjectDependencies takes input source,destination objects.
Sample Input : (source,destination)
Output : Error_list(list)

Installation

  • Use Pip to install the module

    pip install draup-django
    

Usage :

  • Sample model :

      class parent(models.Model):
        name = models.CharField(max_length=100)
    
      class child(models.Model):
        parent = models.ForeignKey(parent, on_delete=models.CASCADE) 
        name = models.CharField(max_length=100)
    
  • Parent Table :

    id Name
    1 Alice
    2 Tom
  • Child Table :

    id Name parent_id
    1 Bob 1
    2 Jack 2
  • Code :

     from draup_django import utility
     m = models.parent
    
     """
     Get Prompt Message
     """
    
     error_list,prompt_message = utility.getAffectedObjects({'id':1},m)
    
     """
     Deletion with all dependent objects
     """
     error_list = utility.deleteObject({'id':1,'force_delete':True},m)
    
     """
     Transferring Object dependencies
     """
    
     source = m.objects.filter(id=1).first()
     destination = m.objects.filter(id=2).first()
     error_list = utility.updateObjectDependencies(source,destination)
    
  • Output : Prompt Message of getAffectedObjects function

    [{'message': 'This object has been used in child 1 times.', 'model_name': 'child', 'Parent models': '', 'count': 1}] 
    
  • Note :

    • Every function returns the error_list, and hence only the operation is successful only if it is empty.

    • 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.

    • Updated Child Table:

      id Name parent_id
      1 Bob 2
      2 Jack 2

Limitation :

  • updateObjectDependencies will not work in case of unique constraint,one to one field in model.
  • Please feel free to share your thoughts and feedback at info@draup.com .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

draup_django-1.0.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

draup_django-1.0.0-py2-none-any.whl (6.1 kB view details)

Uploaded Python 2

File details

Details for the file draup_django-1.0.0.tar.gz.

File metadata

  • Download URL: draup_django-1.0.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for draup_django-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fce395b4735ac1fc7cd534a8e5fb6308265aec6da410b769fa7f5c5cc3ee2279
MD5 35d7d5fba7b9d3f4068d4163f081a8a1
BLAKE2b-256 f3903e85d991e8280069de4f5a2fcffb7c4cca2b850a4fa7f6ae2339a1f88524

See more details on using hashes here.

File details

Details for the file draup_django-1.0.0-py2-none-any.whl.

File metadata

  • Download URL: draup_django-1.0.0-py2-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for draup_django-1.0.0-py2-none-any.whl
Algorithm Hash digest
SHA256 1f1d32d65f46987baab0abc2144f8a8d070655ed667e327526eb0d94232f14fa
MD5 6ed8ae342e976ef4f51c2151973ffda6
BLAKE2b-256 37182b5d9824c98822d32dca22d778242ddb7fc5745ba47f3343a34aba76d9c6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page