Package: draup-django
draup_djangoDelete, Update functionality for normalised modelsUse-Case :Draup Djangoprovide
stateful delete, update functionality at ORM(object relational mapping)level.Table of Content :Stateful Delete/UpdateGet Affected ObjectsDelete ObjectUpdate ObjectInstallationStateful Delete/UpdateBelow are functions inorder to get the stateful delete/updateGet Affected ObjectsList out all dependent objects(Prompt-Messages).getAffectedObjectstakes input dict with id as key and reference of model.Sample Input : ({'id':1},model_reference)
Output : Error_list(list),prompt messages(list)Delete ObjectDelete object with all the dependent objects.deleteObjecttakes 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 ObjectTransferring Object dependencies from one object to another object.updateObjectDependenciestakes input source,destination objects.Sample Input : (source,destination)
Output : Error_list(list)InstallationUse Pip to install the modulepip install draup-djangoUsage :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 :idName1Alice2TomChild Table :idNameparent_id1Bob12Jack2Code :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 ofgetAffectedObjectsfunction[{'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 TableupdateObjectDependenciesfunction will transafer object dependency fromid:1toid:2so parent_id ofBobwill become2.Updated Child Table:idNameparent_id1Bob22Jack2Limitation :updateObjectDependencieswill not work in case of unique constraint,one to one field in model.Please feel free to share your thoughts and feedback atinfo@draup.com.About Draup :Draupis 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.