MCPcopy Index your code
hub / github.com/ormar-orm/ormar / delete

Method delete

ormar/models/model.py:322–343  ·  view source on GitHub ↗

Removes the Model instance from the database. Sends pre_delete and post_delete signals. Sets model save status to False. Note it does not delete the Model itself (python object). So you can delete and later save (since pk is deleted no conflict will arise)

(self)

Source from the content-addressed store, hash-verified

320 return self
321
322 async def delete(self) -> int:
323 """
324 Removes the Model instance from the database.
325
326 Sends pre_delete and post_delete signals.
327
328 Sets model save status to False.
329
330 Note it does not delete the Model itself (python object).
331 So you can delete and later save (since pk is deleted no conflict will arise)
332 or update and the Model will be saved in database again.
333
334 :return: number of deleted rows (for some backends)
335 :rtype: int
336 """
337 await self._emit_signal("pre_delete", instance=self)
338 expr = self.ormar_config.table.delete()
339 expr = expr.where(self.pk_column == (getattr(self, self.ormar_config.pkname)))
340 result = await self._execute_query(expr)
341 self.set_save_status(False)
342 await self._emit_signal("post_delete", instance=self)
343 return result
344
345 async def load(self: T) -> T:
346 """

Callers 15

run_queryFunction · 0.45
delete_itemFunction · 0.45
cleanupFunction · 0.45
cleanupFunction · 0.45
_cleanupFunction · 0.45
test_delete_and_updateFunction · 0.45
test_queryset_methodsFunction · 0.45
test_signal_functionsFunction · 0.45
test_model_crudFunction · 0.45
test_deleteFunction · 0.45

Calls 3

_emit_signalMethod · 0.95
_execute_queryMethod · 0.95
set_save_statusMethod · 0.80

Tested by 15

cleanupFunction · 0.36
cleanupFunction · 0.36
_cleanupFunction · 0.36
test_delete_and_updateFunction · 0.36
test_queryset_methodsFunction · 0.36
test_signal_functionsFunction · 0.36
test_model_crudFunction · 0.36
test_deleteFunction · 0.36
test_model_crudFunction · 0.36