3

I am trying to set up a Facebook-like activity notification system using Django-Activity-Stream.

The library provides a special action signal for creating the actions. According to the documentation, to trigger this action,

You can do it through custom forms or by overriding predefined model methods, such as Model.save(). The logic is to simply import the action signal and send it with your actor, verb, target, and any other important arguments. For example, action.send(request.user, verb='reached level 10')

However, I have an intermediate through model from which the action signal has to be sent. Since Model.save() method is not called when M2M add() or remove() methods are instead used, I want to know if there is any way to override those add() and remove() methods.

I have thought about using M2M changed signals but soon realized that I wouldn't be able to easily access request.user in M2M changed signals. (I need to always know who request.user is to generate any useful activity notifications). I am concerned that accessing a user instance in a signal (by creating a separate middleware to store request.user in a thread, for example) may be costly and unsafe. If it is a reliable option, please tell me.

Junes
  • 63
  • 1
  • 5

0 Answers0