0

I'm using the django console to try to test a query on my sqllite DB.

The table's model starts with:

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,
    )
    ........

Here is my attempt at testing in the django console:

>>> 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

As you can see Message.objects.all() works. But when I try to filter by a particular field having a positive value I get the error. What am I doing wrong?

1 Answer 1

2

The syntax of your field lookup is incorrect. I suggest you review the documentation for the gt lookup.

In your particular case:

o = Message.objects.filter(in_reply_to_id__gt=0)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.