[Django]-Django: Filter objects by integer between two values

34👍

Try this;

x = 170
Dataset.objects.filter(i_end_int__gte=x,i_begin_int__lte=x)

where;
gte = greater than equal to
lte = less than equal to

3👍

Dataset.objects.filter(i_begin_int__lte=170, i_end_int__gte=170)

Filter where i_begin_int is less than 170 AND the i_end_int value is greater than 170.

SQL equivalent: SELECT * FROM appname_dataset WHERE i_begin_int <= 170 AND i_end_int >= 170

Leave a comment