django-auditlog icon indicating copy to clipboard operation
django-auditlog copied to clipboard

Accessing related child objects (deleted ones)

Open eddielu opened this issue 2 years ago • 1 comments

I have an app with the following structure:

class Show(models.Model):
  name = models.CharField(max_length=255)

class ShowPerformer(models.Model):
  show = models.ForeignKey(Show, related_name="performers")
  name = models.CharField(max_length=255)

class ShowGuest(models.Model):
  show = models.ForeignKey(Show, related_name="guests")
  name = models.CharField(max_length=255)

but ShowPerformer's and ShowGuest's could be deleted at any time. I want to be able to see all previously related Performers and Guests LogEntry's from just a Show object, including LogEntry's which show performers and guests being deleted. Does anyone have any suggestions on how to accomplish this?

I saw this suggestion: https://github.com/jazzband/django-auditlog/issues/453, but should I make additional_data indexable for faster access? Otherwise, crawling through each LogEntry could be prohibitively slow when I want to see which performers and guests were deleted from a show's perspective.

Thanks so much!

eddielu avatar Jul 13 '23 07:07 eddielu

You could write a boolean field for them called Active. and create a function under the performer and guest class called delete(), which when called only assigns a False value to Active.

Hope this could help!

Ayobamidele avatar Jul 18 '23 11:07 Ayobamidele