5👍
Basically the solution you’re proposing yourself is called long polling. Django can’t do this out of the box, but there are several add-on solutions, i.e. here. It wouldn’t be too hard to whip it up yourself with some clever $.ajax calls on the client side.
A more thorough solution would not be to use long polling directly, but to only use it as a fall back for other server-side initiated events, like WebSockets and Server-Sent Events (SSE). These are however are harder to implement, because the WSGI specs don’t offer these. You will have to have either a webserver that handles this outside of WSGI (Tornado comes to mind) or have another webserver (probably node.js) or an event handler like gevent that handles the messages the server sends through WebSockets/SSE.
Socket.io provides a fall-back from WebSockets to long polling and you would need something like this to get things done on the Django side.
There’s a rather good blog post about socket.io, django and gevent here.
-1👍
You should probably use django signals:
https://docs.djangoproject.com/en/1.7/ref/signals/
So the template can be updated each time the db change.
You can use for example post_save signal sent each time the save() method is called.
A simpler approach is to refresh the template at a choosen rate though it’s not optimized.
- [Django]-Django middleware process_view get view class?
- [Django]-Django error "'ImageFieldFile' object has no attribute 'replace'"
- [Django]-How to extend django abstract base model by inheritance?
- [Django]-Django – Optimal way to sort models by boolean operation