Search code examples
djangopostgresqlpsycopg2cometpostgresql-9.6

How to get time stamp of database update using psycopg2


I am implementing HTTP streaming with Django. When a user opens a webpage, there is a connection made to the server which returns back data when a new entry is made to the postgresql table.

Let's call the model "M", the model which when updated returns back the data to the client I have a view get_update which does the timestamp checking and returns back data. How can I go about doing it?


Solution

  • Without seeing your code it's hard to know, but from what I understand you're trying to query the last time a table was updated. If that's correct, I would just add a "last_updated" attribute on your model and query that, like so:

    models.py

    class YourModel(models.Model):
        last_updated = models.DateTimeField(auto_now=True)
    

    views.py

    def get_update():
        time_updated = YourModel.objects.last().last_updated
        return(time_updated)