I would like to implement a kind of "real-time" notification system in my Django application.
I would store some messages destined to a specific user in my database. When a user is logged in the application, if there is a notification for him in the database, then the application displays it using the messages framework. When he clicks on the message, it is deleted from the database.
I am a bit stuck on the "fetch the data every minute" thing. I heard of celery (http://docs.celeryproject.org/en/latest/#), but I would like to be sure it is the way to go there before diving in, because it seems a bit complicated to set up and use.
If there is an easy way to daemonise a django fonction, or if something similar to what I want to do already exist, I would appreciate any hint !
If is just a simple task, you may do with Ajax.
Just declare one URL for the ajax query:
then in your
my_app/views.py
:That should do on the server side. On the client side it would be lovely to use jQuery with the
$.ajax
function and do this:Is just a simple set up, a bit of code in server-side and a bit of code in client-side.
If you are planning to develop a heavily real-time based application then you should rely on a better library, but if you only need to do a little query asynchronous then you may consider this way.
Here is a good and simple ajax tutorial provided by the W3Schools to help you understand Ajax, and here you can find useful information about polling with ajax/jquery.
Good luck!