0

For my CRM I am trying to create an History model, that should store every change or action made on a specific Ticket (aka Customer Request). In this scenario two type of users are involved: Resources and Customers.

Since both can make an action that should be stored in the History table (ex. Customers can open the ticket and Resources can close it) I was wondering what is the right way to achieve this as a Foreign Key (actor)

class TicketHistory(models.Model):
    ticket = models.ForeignKey("Tickets", on_delete=models.PROTECT, related_name="ticket")
    action = models.ForeignKey("HistoryActions", on_delete=models.PROTECT, related_name="action")
    resourceActor = models.ForeignKey("Resources", ...)
    customerActor = models.ForeignKey("CustomerUsers" ...)
    date = models.DateTimeField(auto_now_add=True)

As you can see I've initially decided to create two different fields, but I don't think it is the best solution. How would you do this?

2 Answers2

1

I'd just use: https://django-simple-history.readthedocs.io/en/latest/

Simple app - tracks all changes on an app/model

Life By Ben
  • 186
  • 5
1

You can use the admin site model log answered here, or you can use django-simple-history. This last one make the same that admin site history log. Choose the one you like.

Jorge Luis
  • 902
  • 12
  • 25