开发者

Django Poll for new records

开发者 https://www.devze.com 2023-01-21 08:21 出处:网络
开发者_开发百科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 requ

开发者_开发百科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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消