diff --git a/redisco/models/base.py b/redisco/models/base.py index 3cf70b989..43b3bd921 100644 --- a/redisco/models/base.py +++ b/redisco/models/base.py @@ -343,7 +343,6 @@ def key(self, att=None): return self._key[self.id][att] else: return self._key[self.id] - def delete(self): """Deletes the object from the datastore.""" pipeline = self.db.pipeline() @@ -352,6 +351,16 @@ def delete(self): pipeline.delete(self.key()) pipeline.execute() + #Clean up procedure used for cleaning up {ModelName}:id + #when there are no objects left inside {ModelName}:all. + #This only occurs when all the objects have been deleted. + #So,{ModelName}:id is left with the the last total count """ + + any_left = redisco.get_client().hexists(name=self._key,key=self._key['all']) + if not any_left: + pipeline.delete(self._key['id']) + pipeline.execute() + def is_new(self): """ Returns True if the instance is new.