Django signals for processing a simple user notification system
<p>I'm learning to code and have a live Django project to keep me motivated. In my Django app, users leave comments, while others reply to the said comments. </p>

<p>Everytime a user refreshes their home page, I calculate whether they've received any new replies on their previously-left comments, and show a notification if they did.</p>

<p>This doesn't scale, because if a user has left a ton of comments and hence received a ton of replies, the calculation takes longer than for <em>lurkers</em> who don't create content. I want to improve the experience for these content creators. </p>

<p>Reading <a href="http://www.koopman.me/2015/01/django-signals-example/" rel="noreferrer">deeper into it</a>, I've figured Django signals are the way to go. For instance, every time a new reply is left, I can fire a post_save() signal, which can be received and update the notification for the user. This way, notifications will update as replies are left - which is the way it should be.</p>

<p>I'll have to refactor my code, and I'm still hazy on the implementational details of the above. Can anyone provide me a quick illustrative example of how I can accomplish the above? It's going to get me started.</p>

<hr>

<p>Currently, user reply processing is handled in the <code>form_valid</code> method of a CBV in my views.py <code>class PublicreplyView(CreateView)</code>. I'm guessing I can include the following as a method in my CBV? </p>

<p><code>from django.db.models.signals import post_save
post_save.connect(form_valid, sender=User)</code></p>

<p>And then elsewhere I have a different CBV that processes the notifications for every user once they refresh the home page. I guess I'll need to completely re-write that? Like I said, I'm hazy on that front.</p>

<p>Would love to have someone guide me what to do with an illustrative, simple example. Thanks!</p>

<hr>

<p>p.s. I'm on Django &lt; 1.8. </p>