我正在使用django控制台尝试在我的sqllite数据库上测试查询。
表的模型以:
开头class Message(models.Model):
mailbox = models.ForeignKey(Mailbox, related_name='messages')
subject = models.CharField(max_length=255)
message_id = models.CharField(max_length=255)
in_reply_to = models.ForeignKey(
'django_mailbox.Message',
related_name='replies',
blank=True,
null=True,
)
........
以下是我在django控制台中进行测试的尝试:
>>> from django_mailbox.models import Message
>>> o = Message.objects.all()
>>> o
[<Message: Get Gmail for your mobile device>, <Message: Tips for using Gmail>, <Message: Welcome to Gmail>, <Message: Getting started on Google+>, '...(remaining elements truncated)...']
>>> o = Message.objects.filter(in_reply_to > 0)
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'in_reply_to' is not defined
正如您所见,Message.objects.all()可以正常工作。但是当我尝试通过具有正值的特定字段进行过滤时,我得到了错误。我做错了什么?
答案 0 :(得分:2)