[Answer]-Update an object after deleting a value from it


Just working off your own code, then

if data.count > 0:
    data.count = None
#continue with some stuff and lastly call .save()

should suffice.

Calling .delete() will, in Django, remove the entire object.

However if you want to delete the attribute of that said object, you’re gonna have a bad time, especially when you’re working of an object that inherits from models.Model but let’s go ahead and do it anyways

del productObj.count #from the object

and if you want it stripped from the model you would have to delete it from the models _meta fields which would be the property -> Model._meta.fields

Daniel Roseman explains it brilliantly here

Leave a comment