1

I have an application that has both posting and wishlist models. Users create posting and wishlist objects and hypothetically when they delete these objects that means they successfully bought or sold whatever the item was.

I want to continuously count the number of objects that are deleted for each model and I am not sure how to do it?

This way I can keep track of how successful customers are being.

Any recommendations would be greatly appreciated.

Programmingjoe
  • 2,169
  • 2
  • 26
  • 46

2 Answers2

2

You have many ways to do this:

  1. Implement an auditing mechanism; using any number of audit applications available.

  2. As of django 1.9, the delete() method returns the number of objects deleted. You can store this value in a separate model and track it.

  3. Don't actually delete, but implement a "soft-delete" which is a form of a flag that marks records as deleted but doesn't remove them from the table. You can then add an additional field to track any meta-data you would want to track for the delete option. The easiest way to implement this is to override delete() on the model.

Flimm
  • 136,138
  • 45
  • 251
  • 267
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
1

One solution is to never hard delete any of the objects, but keep a boolean called "is_deleted" in your model. This way, you can count the number of deleted objects, and you can also count specific elements of the deleted objects. You might want to override the delete() fuction, see this SO question on how to do this:

Downside is of course that you have to store the elements. Also, sometimes a delete should cascade. You can for instance use a library like django-safedelete or django-softdelete

Community
  • 1
  • 1
Martin Hallén
  • 1,492
  • 1
  • 12
  • 27