shadyabhi
shadyabhi

Reputation: 17234

Sending notification to the user on database change

I am building a cafeteria management system in which there are two types of users;customres & counter owners.

For each dish offered in cafeteria, there is aunique dish.id associated to it.

Till now, I have dome something like student sends a POST request with dish,id and counter number to a URL which updates the "orders table'(which has PK as id). When the dish is prepared, the counter owner presses "Prepeared" button.

At this point, I want the customer whose order is next to what is prepared to get notified that "Your order preparation is in progress."

How should I do it? One way is to simply make a view which has its argument as customer.id & status and it replies with True or Flase. I can simply poll the URL and provide the notification if I recieve True.

But, I feel like polling is not a better approach as there will be so many customers logged in and each will poll to the server which is not acceptible. Any better way?

Upvotes: 6

Views: 2521

Answers (5)

Mp0int
Mp0int

Reputation: 18727

There are two possible ways...

  1. Override your related models admin.py save methods like it described in here

  2. You can use signals as it described in here

Using admin.save_model is easier and suit your needs. Since you have table_id's, you may set that tables order status to "preparing".

Upvotes: 0

Jerzyk
Jerzyk

Reputation: 3752

It really depends what you really need.

If notification can be sent ad part of user activity, simply add a user message, and it will be displayed whenever user do an action on the page. django.contrib.messages plus few lines in your main html template will do it.

But if you want the notification to be interactive - you can use one of the few PUSH options

Interesting links:

From the servers side, there are few options available, the simplest is Green Unicorn. Using it will allow you to have few thousands connections open and managed by only few processes.

Upvotes: 2

andrei
andrei

Reputation: 8582

I don;t know if u understood corectly but i think you should use websockets

 http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/ 

Upvotes: 1

hynek
hynek

Reputation: 4126

The easiest way of a "push" without recurring polling would be "long polling", where the client starts an request and gets the answer as soon as it's available. You have to use a well scaling server anyway but it doesn't get hammered at least hammered all the time.

There are better but more complicated ways for server pushes, have a look at the article I linked above.

Upvotes: 0

Myth
Myth

Reputation: 1602

As we cannot push data over http, I think polling is the only option left.

You can you a ajax request to poll, Which can be used to update some other stats ( if any ) as well to make it more interactive :)

Upvotes: -1

Related Questions