1

这是我的错误,我真的找不到与我的问题类似的任何东西:

from django.db.models import Q    
_entry = Entry.objects.get(Q(slug=slug, author=self.author) & ~Q(id=self.id))

TypeError:一元操作数类型错误〜:'Q'

4

2 回答 2

2

您尝试对 s 执行的操作的替代方法是Q使用filter()++ exclude()get()

_entry = Entry.objects.filter(slug=slug, author=self.author).exclude(id=self.id).get()
于 2015-01-01T22:26:00.767 回答
0

不仅'&'而且逗号','在django Q对象中代表AND,所以你也可以尝试:

from django.db.models import Q    
_entry = Entry.objects.get(Q(slug=slug), Q(author=self.author) , ~Q(id=self.id))

尽管我无法重新创建您收到的错误。还请确保 slug、self.author 和 self.id 具有正确类型的数据以进入各自的字段。

是完整参考的文档

于 2015-01-02T00:53:19.043 回答