g = Goal.objects.filter(Q(title__contains=term) | Q(desc__contains=term))
如何添加到我的filter
那user=request.user
?在Django中的Q对象查询集
这不起作用:
g = Goal.objects.filter(user=request.user, Q(title__contains=term) | Q(desc__contains=term))
型号:
class Goal(models.Model):
user = models.ForeignKey(User)
title = models.CharField(max_length=255)
desc = models.TextField()
请先显示您的模型。 – alecxe
@alecxe我更新了问题 – user3207076
不要只说“这不行”,请包含回溯。在这种情况下,回溯是'SyntaxError:关键字arg'之后的非关键字arg,它正确地解释了发生了什么。 – Alasdair