我有一个由django构建的博客应用程序,如果有新的评论,我想通知博客作者,所以这里是我所做的
class Blog(models.Model):
lastview = models.DateTimeField('self last view date')
class Comment(models.Model):
blog = models.ForeignKey(Blog)
timestamp = models.DateTimeField('comment date')
user_blog_list = Blog.Objects.filter(author = request.user)
user_blog_com = {}
for blog in user_blog_list:
user_blog_com [blog] =list(Comment.objects.filter(blog = blog ))
现在user_blog_com
是dict
接下来,我需要将每条评论的时间戳与blog的lastview进行比较,以确定博客作者是否查看了评论,但我不知道如何查看。在
我想要的是一个像光盘一样的
{
(Blog: blogname):[(Comment:unviewed_comment),(Comment:unviewed_comment)],
}
请帮忙!!!在
我试试这个
user_blog_com = {}
for blog in user_blog_list:
user_blog_com [blog] =list(Comment.objects.filter(blog = blog ,timestamp > blog.lastview ))
get an error: non-keyword arg after keyword arg
我还没有测试过,但是下面的内容应该会给你每个博客的新评论列表。在
F() Expressions允许您逐行引用数据库中的值。除此之外,您只需要请求所有新的注释
timestamp__gte=blog__lastview
,其中当前用户是作者。{{cd3>你可以使用另一个实例,而不需要访问cd3}。在如果您必须在字典中包含这些信息(我想知道为什么会是这样…),那么您可以执行以下操作:
^{pr2}$比你试图构建它的方式更具可读性和表达力。在
试试这个
这可能对你有帮助。在
相关问题 更多 >
编程相关推荐