Answer the question
In order to leave comments, you need to log in
Comparing django fields when getting base rows?
I have a table in which there are two fields of the int type.
When receiving records through a filter, I want to compare the values of these fields, here is an example:
queryset.filter(field1__gt=field2)
Ie, get all records where field1 is greater than filed2. Is it possible to implement this through django?
Answer the question
In order to leave comments, you need to log in
I found a solution in the documentation, they pushed it very far.
You need to use method F
Here is the solution to my problem:
from django.db.models import F
queryset.filter(field1__gt=F("field2"))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question