Django 民意调查新记录
在 ajax 中,我正在轮询 django url 以检索最新记录。我不想显示之前检索到的任何记录,并且只想为每个轮询请求检索 1 条记录。
最好的方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我对你的问题的理解没有错误,你可以使用 Meta
class 的 get_latest_by 属性,并调用可以满足你的目的的方法latest()`,以便为了不检索记录两次,您可以使用 obj.pk > your_prev_retired_pk。
If I'm not wrong in understanding your question, You may go for
get_latest_by attribute of
Metaclass and call the method
latest()` which may serve your purpose, in order not to retrieve the record twice you may use the obj.pk > your_prev_retired_pk.唔。我可以立即想到两种方法来做到这一点——肯定还有更多。
您可以添加一个名为“already_retrieved”的字段,并将其设置为 True 对于那些已经检索到的字段,然后只获取Whatever.objects.filter(already_retrieved=False)。
另外,如果它们按 pk 排序,您可以跟踪自己在 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.