Sending notifications to users in web applications
I am developing a Cafeteria Management System using Django (my first project in 开发者_高级运维web-development, so yes I am a beginner) in which there are two kind of users "Counter Staff" & "customers".
Now, the current order's list is shown as table on the counter side. On the customer's side, there is a table that displays current available dishes.
There are two types of events:-
- Customer orders the food.
- Counter enables/disables a dish as per availability.
So, if the customer orders food, I want the table at the counter side to be added For the second event, if counter enables/disables a dish, I want the customer's side table to add/remove dish row.
I want a real-time solution. So, how do I implement it ?
It seems like you need both users to poll the server. Use timers in your JavaScript to make requests to the server (this is called polling) every minute or so. Then use jQuery's great traversal and manipulation utilities to rebuild the tables in the browser.
Or if you don't want to implement updating the view using JavaScript and prefer to stick with the view rendering you have with Django..
Have an endpoint on the server that returns the last time a dish was added or removed. Have a timer that compares that time with the time the page was rendered. If a dish has been added or removed, refresh the page via JavaScript. If you do this, don't compare the client time with the server time. You'll need to embed the server time in the page as a JavaScript variable.
You may want to take a look at signals:
Django Sisgnals
Long polling is a preferred solution.
精彩评论