Django: Filter objects by integer between two values

后端 未结 2 1363
梦毁少年i
梦毁少年i 2020-12-31 06:09

I\'m struggling with a Django filtering problem I couldn\'t solve so far. I have a database with from/to integers, and I need a Django Filter that returns any objects where

相关标签:
2条回答
  • 2020-12-31 06:45
    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

    0 讨论(0)
  • 2020-12-31 06:53

    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

    0 讨论(0)
提交回复
热议问题