Ajax reload method acting on a Django table

320 views Asked by At

I currently have a simple HTML table which is being served by a django app in the following way:

<table id="List">
<th>
    <td data-field="ID" align="center">ID</td>
    <td data-field="Name" align="center">Name</td>
</th>

{% for item in filter %}
    # 'filter' is the result of applying some filter on a query set
    <tr value="{{ item.ID }}">
        <td align="center">{{ item.ID }} </td>
        <td align="center">{{ item.Name }} </td>
    </tr>
{% endfor %}
</table>

I would like this table to respond 'live' to changes in the database (e.g. a change to the 'Name' field for some record). I have looked into server push solutions (django+twisted, django+swampdragon, django+angular) but they seem overly complicated for what I need here.

I then found out about $.ajax's reload() method which seems perfect BUT it seems from the examples I've found that I would need to form the table by passing jsonified records instead of what I am currently doing.

Can anyone advise me on:

  • If this is a viable solution
  • Explain how you might construct a table from a django database in such a way that ajax would be able to update the contents every few seconds.
0

There are 0 answers