0

Basically what i'm trying to accomplish is a query like this but using QuerySet:

SELECT value1, value2 FROM table WHERE value1 > value2

How do i do this? Thanks for your help.

1

2 Answers 2

1

Use F expressions to have a query field refer to another.

from django.db.models import F
Entry.objects.filter( n_comments__gt=F('n_pingbacks') )
Sign up to request clarification or add additional context in comments.

Comments

0

You need to use the F() expression

In your example it would look like:

from django.db.models import F
Table.objects.filter(value1__gt=F('value2')).values('value1', 'value2')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.