Re: Django Signal DataBase Change on Template
A lot of JavaScript is involved in doing this. I see three possible approaches:
1. Use a timer in JavaScript to cause the page to reload itself frequently. This isn't pretty. The page will glitch as it reloads. You will be reloading the whole page each time, which includes much that the browser already has. There is a trade off between update latency and useless request rate. If your GPS updates come in at a dependable rate you can make a good guess for polling rate.Don't do this.
The only advantage that it has is that it will work with a browser that doesn't support AJAX (read very old browser).
The Django code is easy. No signals are required. ORM does a fetch for current coordinates for each request. If you have lots of users you will will have lots of database traffic, as well as lots of web traffic. You can reduce the database overhead by caching the current set of coordinates in RAM (and maybe not use the database at all, if you don't need to keep historical records. If you do use RAM, beware of threading issues on this shared data.
An outline is to have the server include a timestamp when it does send data. The request includes the timestamp, and if the server has no new information, it sends an empty response (should be as cheap as a 304 response, but changing the response code is easy, and is arguably more correct, but may or may not be harder on the JavaScript side).
Should work on all modern browsers.
The Django code is still easy. In order to use RAM cache and still just send what has changed, you will need to annotate each unit's position with a timestamp (and it still wants to be the server timestamp, not the GPS time of the sample) so that the view code can search for those newer than the request's indicated time. Think even harder about threading issues, though I'm still pretty sure that I could do this without locks.
On Thu, Aug 1, 2013 at 10:54 AM, Saif Jerbi <m.jerbi.saif@gmail.com> wrote:
I'm building a GPS Tracking System using Django, i should have a grid on my template that display real time information of cars (position,vitesse, temperature...). GPS send data to Postgres DataBase via a module that parse Data and saved it in specific table. What i need is how to make my Web App display data in real time? (when a row is inserted in Db, how can i display it in grid)
i tried this package https://pypi.python.org/pypi/django-db-signals/0.1.1, but my DataParser is external from my django web app, it work independently from other side
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home