Skip to main content
 首页 » 编程设计

python之如何检索不是由用户创建的对象

2024年11月24日8soundcode

<分区>

这个问题可能很奇怪,但我想检索除用户登录创建的对象之外的对象

好吧,我在我看来尝试了这段代码

def getobjects(request): 
    products=Products.objects.filter(user!= request.user) 

但不起作用。

在模型中

class Products(models.Model): 
    name=models.Charfield() 
    user=models.ForeignKey(User) 

我需要有关正确查询功能的帮助来处理这个问题。提前致谢