views:

28

answers:

2

In ajax I am polling a django url to retrieve the latest records. I do not want to display any records I have retrieved previously and I only want to retrieve 1 record for each poll request.

What would be the best way to do this?

A: 

Hmm. You could do it two ways that I can think of off the bat - there are surely more.

You can add a field called "already_retrieved" and set it to True for those fields that have already been retrieved, and then only grab Whatever.objects.filter(already_retrieved=False).

Also, if they are in order by a pk, you could just keep track of how far you are in the list of pk's.

Justin Myles Holmes
+1  A: 
class Article(models.Model):
    headline = models.CharField(max_length=100)
    pub_date = models.DateField()
    expire_date = models.DateField()
    class Meta:
        get_latest_by = 'pub_date'

>>> from mysite.models import Article
>>> Article.objects.latest()

If I'm not wrong in understanding your question, You may go for get_latest_by attribute ofMetaclass and call the methodlatest()` which may serve your purpose, in order not to retrieve the record twice you may use the obj.pk > your_prev_retired_pk.

Tumbleweed