How to do a less than or equal to filter in Django queryset?

前端 未结 1 858
南笙
南笙 2020-12-12 15:33

I am attempting to filter users by a custom field in each users profile called profile. This field is called level and is an integer between 0-3.

If I filter using e

相关标签:
1条回答
  • 2020-12-12 16:06

    Less than or equal:

    User.objects.filter(userprofile__level__lte=0)
    

    Greater than or equal:

    User.objects.filter(userprofile__level__gte=0)
    

    Likewise, lt for less than and gt for greater than. You can find them all in the documentation.

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